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

  1. Click Menu Design Projects, then Driver_department_traffic_violations.
  2. Click Add Asset Test Scenario.
  3. In the Create new Test Scenario window, enter the following values:

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

    Figure 5.1. Speed test results screen

    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

  1. Click Menu Design Projects, then Driver_department_traffic_violations.
  2. Click Add Asset Test 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.myspace.driver_department_traffic_violations.
  4. Click Ok.
  5. Click +GIVEN to open the New input window.
  6. Select Driver from the Insert a new fact 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 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 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 menu and click OK.
  16. Click ( 6191 ), and 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 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 menu and click OK.
  24. Enter suspend in the state: equals field.
  25. Click Save, and 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.2. Suspension test results screen

    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

  1. Click Menu Design Projects, then Driver_department_traffic_violations.
  2. Click Suspend due to total points Copy, enter Suspend due to multiple violations in the New Asset Name field, and click Make a Copy.
  3. Click Space MySpace Driver_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 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 points violation2 field.
  8. In the totalPoints field, change the value from 10 to 5.
  9. Click Save, and then click Save to confirm your changes.
  10. Click Run scenario.

    Figure 5.3. Suspension test results screen

    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.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.