Red Hat Training

A Red Hat training course is available for Red Hat Decision Manager

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

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 and Driver data objects
  • Created the speed violation guided decision table

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click ProjectsCreate New AssetTest Scenario.
  3. In the Create new Test Scenario window wizard, enter the following values:

    1. Test Scenario: Speed limit 10-20.
    2. Package: select com.myteam.driverdepartmenttrafficviolations.
  4. Click Ok.
  5. Click +GIVEN to open the New input window.
  6. Select Violation from the Insert a new fact pull-down menu.
  7. Enter violation in the Fact name field and click Add.
  8. Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
  9. Select speedLimit from the Choose a field to add pull-down menu and click OK.
  10. Click 6191 , then click Literal value next to speedLimit.
  11. Click Literal value in the Field value window, then enter 40 in the speedLimit field.
  12. 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.
  13. Click 6191 , then click Literal value next to Literal value.
  14. Enter Speed in the type field.
  15. Click Insert 'Violation'[violation], and select actualSpeed from the Choose a field to add pull-down menu, and click OK.
  16. Click 6191 , then click Literal value next to Literal value.
  17. Enter 55 in the actualSpeed field.
  18. Click +Expect to open the New expectation window.
  19. Expand the Rule pull-down menu, select Row 1 SpeedViolationRule, and click OK.
  20. Click +GIVEN to open the New input window, enter trafficViolation in the Activate rule flow group field, and click Add.
  21. Click +Expect to open the New expectation window and click Add next to Fact value: violation.
  22. Click Violation 'violation' has values: to open the Choose a field to add window.
  23. Select fineAmount from the Choose a field to add pull-down menu and click OK.
  24. Enter 100.0 in the fineAmount: equals field.
  25. Click Violation 'violation' has values: to open the Choose a field to add window.
  26. Select points from the Choose a field to add pull-down menu and click OK.
  27. Enter 1 in the points: equals field.
  28. Click Save, then click Save to confirm your changes.
  29. Click Run scenario.

    Figure 5.2. Speed test results screen

    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 and Driver data objects
  • Set the Driver License Suspension rules and actions

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Create New AssetTest Scenario.
  3. In the Create new Test Scenario window wizard, enter the following values:

    1. Test Scenario: Suspend due to total points.
    2. Package: select com.myteam.driverdepartmenttrafficviolations.
  4. Click Ok.
  5. Click +GIVEN to open the New input window.
  6. Select Driver from the Insert a new fact pull-down menu.
  7. Enter driver in the Fact name field and click Add.
  8. Click Add a field located under 'Driver'[driver] to open the Choose a field to add window.
  9. Select totalPoints from the Choose a field to add pull-down menu and click OK.
  10. Click 6191 next to totalPoints, click Literal value, then enter 10 in the totalPoints field.
  11. Click +GIVEN to open the New input window.
  12. Select Violation from the Insert a new fact pull-down menu.
  13. Enter violation in the Fact name field and click Add.
  14. Click Add a field located under Insert 'Violation'[violation] to open the Choose a field to add window.
  15. Select points from the Choose a field to add pull-down menu and click OK.
  16. Click 6191 , then click Literal value next to Literal value.
  17. Enter 10 in the points field.
  18. Click +Expect to open the New expectation window.
  19. Expand the Rule pull-down menu, select DriverLicenseSuspensionRule, and click OK.
  20. Click +GIVEN to open the New input window, enter trafficViolation in the Activate rule flow group field, and click Add.
  21. Click +Expect to open the New expectation window and click Add next to Fact value: driver.
  22. Click Driver 'driver' has values: to open the Choose a field to add window.
  23. Select state from the Choose a field to add pull-down menu and click OK.
  24. Enter suspend in the state: equals field.
  25. Click Save, then click Save to confirm your changes.
  26. 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

    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 and Driver data objects
  • Set the driver license suspension rules and actions

Procedure

  1. Log in to Decision Central. Click MenuDesignProjects, then Driver department traffic violations.
  2. Click Suspend due to total pointsCopy, enter Suspend due to multiple violations in the New Asset Name field, and click Make a Copy.

    Figure 5.4. Make a copy window

    Making a copy panel
  3. Click SpacemyteamDriver department traffic violations, and then select the Suspend due to multiple violations Asset.
  4. Click +GIVEN to open the New input window.
  5. Select Violation from the Insert a new fact pull-down menu.
  6. Enter violation2 in the Fact name field and click Add.
  7. Click 6191 next to points, click Literal value, then enter 5 in the pointsviolation2 field.
  8. In the totalPoints field, change the value from 10 to 5.
  9. Click Save, then click Save to confirm your changes.
  10. Click Run scenario.

    Figure 5.5. Suspension test results screen

    Suspension test results screen