Chapter 5. Test Scenarios
Test Scenarios in Red Hat Decision Manager enable you to validate the functionality of rules, models, and events before deploying them into production. A test scenario uses data for conditions that resemble an instance of your fact or project model. This data is matched against a specific set of rules and if the expected results match the actual results, the test is successful. If the expected results do not match the actual results, then the test fails.
After you run all test scenarios, the status of the scenarios is reported in a Reporting panel.
Test scenarios can be executed one at a time or as a group. The group execution contains all the scenarios from one package. Test scenarios are independent, so that one scenario cannot affect or modify the other.
5.1. Testing the speed limit scenario
Test the speed limit scenario using the data that you specified when you created the traffic violation guided decision table.
Prerequisites
- You have created the Driver_department_traffic_violations project.
- You have created the Violation and Driver data objects.
- You have created the SpeedViolationRule guided decision table.
Procedure
-
Click Menu
Design Projects, then Driver_department_traffic_violations. -
Click Add Asset
Test Scenario. In the Create new Test Scenario window, enter the following values:
-
Test Scenario:
Speed limit 10-20
. -
Package: select
com.myspace.driver_department_traffic_violations
.
-
Test Scenario:
- Click Ok.
- Click +GIVEN to open the New input window.
- Select Violation from the Insert a new fact menu.
-
Enter
violation
in the Fact name field and click Add. - Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
- Select speedLimit from the Choose a field to add menu and click OK.
- Click ( ), and then click Literal value.
-
Enter
40
in the speedLimit field. - Click Insert 'Violation'[violation].
- Select type from the Choose a field to add menu in the Choose a field to add window, and click OK.
- Click ( ), and then click Literal value.
-
Enter
Speed
in the type field. - Click Insert 'Violation'[violation].
- Select actualSpeed from the Choose a field to add menu, and click OK.
- Click ( ), and then click Literal value.
-
Enter
55
in the actualSpeed field. - Click +Expect to open the New expectation window.
- Expand the Rule menu, select Row 1 SpeedViolationRule, and click OK.
-
Click +GIVEN to open the New input window, enter
trafficViolation
in the Activate rule flow group field, and click Add. - Click +Expect to open the New expectation window and click Add next to Fact value: violation.
- Click Violation 'violation' has values: to open the Choose a field to add window.
- Select fineAmount from the Choose a field to add menu and click OK.
-
Enter
100.0
in the fineAmount: equals field. - Click Violation 'violation' has values: to open the Choose a field to add window.
- Select points from the Choose a field to add menu and click OK.
-
Enter
1
in the points: equals field. - Click Save, and then click Save to confirm your changes.
Click Run scenario.
Figure 5.1. Speed test results screen
If the values and conditions set in the test scenario meet the requirements as specified in the speed violation guided decision table, the Reporting section at the bottom of the window displays a Success message.
5.2. Testing the driver license suspension scenario
Test the driver license suspension scenario using the data that you specified when you set the Driver License Suspension rules and actions.
Prerequisites
- You have created the Driver_department_traffic_violations project.
- You have created the Violation and Driver data objects.
- You have set the Driver License Suspension rules and actions.
Procedure
-
Click Menu
Design Projects, then Driver_department_traffic_violations. -
Click Add Asset
Test Scenario. In the Create new Test Scenario window wizard, enter the following values:
-
Test Scenario:
Suspend due to total points
. -
Package: select
com.myspace.driver_department_traffic_violations
.
-
Test Scenario:
- Click Ok.
- Click +GIVEN to open the New input window.
- Select Driver from the Insert a new fact menu.
-
Enter
driver
in the Fact name field and click Add. - Click Add a field located under 'Driver'[driver] to open the Choose a field to add window.
- Select totalPoints from the Choose a field to add menu and click OK.
-
Click (
) next to totalPoints, click Literal value, then enter
10
in the totalPoints field. - Click +GIVEN to open the New input window.
- Select Violation from the Insert a new fact menu.
-
Enter
violation
in the Fact name field and click Add. - Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
- Select points from the Choose a field to add menu and click OK.
- Click ( ), and then click Literal value next to Literal value.
-
Enter
10
in the points field. - Click +Expect to open the New expectation window.
- Expand the Rule menu, select DriverLicenseSuspensionRule, and click OK.
-
Click +GIVEN to open the New input window, enter
trafficViolation
in the Activate rule flow group field, and click Add. - Click +Expect to open the New expectation window and click Add next to Fact value: driver.
- Click Driver 'driver' has values: to open the Choose a field to add window.
- Select state from the Choose a field to add menu and click OK.
-
Enter
suspend
in the state: equals field. - Click Save, and then click Save to confirm your changes.
Click Run scenario.
Result
The rule is fired and the driver’s license is suspended because the total number of points is >= 20.
Figure 5.2. Suspension test results screen
If the values and conditions set in the test scenario meet the requirements that you specified when you set the Driver License Suspension rules and actions, the Reporting section at the bottom of the window displays a Success message.
5.3. Testing the multiple violations scenario
Copy the Suspend due to total points asset and modify it to create the driver license suspension scenario for drivers with multiple violations using the data that you specified when you set the Driver License Suspension rules and actions.
Prerequisites
- You have created the Driver_department_traffic_violations project.
- You have created the Violation and Driver data objects.
- You have set the driver license suspension rules and actions.
Procedure
-
Click Menu
Design Projects, then Driver_department_traffic_violations. -
Click Suspend due to total points
Copy, enter Suspend due to multiple violations
in the New Asset Name field, and click Make a Copy. -
Click Space
MySpace Driver_department_traffic_violations, and then select the Suspend due to multiple violations Asset. - Click +GIVEN to open the New input window.
- Select Violation from the Insert a new fact menu.
-
Enter
violation2
in the Fact name field and click Add. -
Click (
) next to points, click Literal value, then enter
5
in the pointsviolation2 field. -
In the totalPoints field, change the value from
10
to5
. - Click Save, and then click Save to confirm your changes.
Click Run scenario.
Figure 5.3. Suspension test results screen
If the values and conditions set in the test scenario meet the requirements that you specified when you set the Driver License Suspension rules and actions, the Reporting section at the bottom of the window displays a Success message.