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 given 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.
Figure 5.1. Speed test scenario screen
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 speed violation guided decision table.
Prerequisites
-
Created the
Driver department traffic violations
project -
Created the
Violation
andDriver
data objects - Created the speed violation guided decision table
Procedure
-
Log in to Decision Central. Click Menu
Design Projects, then Driver department traffic violations. -
Click Projects
Create New Asset Test Scenario. In the Create new Test Scenario window wizard, enter the following values:
-
Test Scenario:
Speed limit 10-20
. -
Package: select
com.myteam.driverdepartmenttrafficviolations
.
-
Test Scenario:
- Click Ok.
- Click +GIVEN to open the New input window.
- Select Violation from the Insert a new fact pull-down 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 pull-down menu and click OK.
- Click , then click Literal value next to speedLimit.
-
Click Literal value in the Field value window, then enter
40
in the speedLimit field. - Click Insert 'Violation'[violation] and select type from the Choose a field to add pull-down menu in the Choose a field to add window, and click OK.
- Click , then click Literal value next to Literal value.
-
Enter
Speed
in the type field. - Click Insert 'Violation'[violation], and select actualSpeed from the Choose a field to add pull-down menu, and click OK.
- Click , then click Literal value next to Literal value.
-
Enter
55
in the actualSpeed field. - Click +Expect to open the New expectation window.
- Expand the Rule pull-down 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 pull-down 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 pull-down menu and click OK.
-
Enter
1
in the points: equals field. - Click Save, then click Save to confirm your changes.
Click Run scenario.
Figure 5.2. Speed test results screen
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
-
Created the
Driver department traffic violations
project -
Created the
Violation
andDriver
data objects - Set the Driver License Suspension rules and actions
Procedure
-
Log in to Decision Central. Click Menu
Design Projects, then Driver department traffic violations. -
Click Create New 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.myteam.driverdepartmenttrafficviolations
.
-
Test Scenario:
- Click Ok.
- Click +GIVEN to open the New input window.
- Select Driver from the Insert a new fact pull-down 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 pull-down 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 pull-down 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 pull-down menu and click OK.
- Click , 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 pull-down 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 pull-down menu and click OK.
-
Enter
suspend
in the state: equals field. - Click Save, 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.3. Suspension test results screen
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
-
Created the
Driver department traffic violations
project -
Created the
Violation
andDriver
data objects - Set the driver license suspension rules and actions
Procedure
-
Log in to Decision Central. 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.Figure 5.4. Make a copy window
-
Click Space
myteam 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 pull-down 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, then click Save to confirm your changes.
Click Run scenario.
Figure 5.5. Suspension test results screen