After you run all test scenarios, the status of the scenarios is reported in a Messages panel.

Test Scenario screen
Figure 1. Test Scenario Screen

Test scenarios can be executed one at the 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.

A basic test scenario requires, at minimum, the following data:

With this data, the test scenario can compare given facts with expected results, according to the related data objects, and validate the configured rules.

For information on adding more advanced test scenario settings, see [test_scenarios_advanced_con].

Procedure
  1. In {CENTRAL}, go to AuthoringProject Authoring and click the project name.

  2. Click Add AssetTest Scenario.

  3. Enter the test scenario name, select the package, and click OK.

    The Test Scenario editor appears.

    5594.png
    Figure 2. Test Scenario Editor
  4. Click the Data Objects tab to verify that all data objects required for the rules you want to test are listed. If not, click New item to import the needed data objects from other packages.

    Data objects from the same package are available by default, but data objects in other packages must be imported.

    For example, consider the package structure org.company.project with these data objects:

    • Fact1 in package org.company

    • Fact2 in package org.company.project

If you create your test scenario in org.company, then Fact1 is available but you must import Fact2.

+ . After confirming or importing the data objects, return to the Editor tab and define the GIVEN and EXPECT data by clicking 5686.png next to each label. Click Save in the editor after you make any changes.

+ The GIVEN section defines the input facts for the test. You can select a particular data object from the model and give it a variable name, called Fact Name in the window, or choose to activate a rule flow group instead. Activating a rule flow group allows rules from the specified rule flow group to be tested by activating the group in advance.

+ .Define GIVEN :6210.png

+ NOTE: For information about adding advanced values to GIVEN fields, see [test_scenarios_advanced_proc].

+ The EXPECT section defines the expected results based on the GIVEN input facts. That is, GIVEN the input parameters, EXPECT these rules to be activated or fired. You can also EXPECT facts to be present and to have specific field values, or EXPECT rules not to fire at all.

+ .Define EXPECT :5611.png

+ You can provide one of three expectations, depending on the data in the GIVEN section:

+

  • Rule: Enables you to check for firing of a particular rule. Either type the name of a rule that is expected to be fired or select it from the list of rules. Click OK.

  • Fact value: Enables you to check a specific object instance and its values. In the following example, given a Customer object with the hasInternetService boolean set to true, we expect the same object to have the hasPhoneService boolean set to true:

+ :factvalues.png

+

  • Any fact that matches: Enables you to check any objects in the working memory and the values of their field. In the following example, given a Customer object which has Internet service, a new object RecurringPayment is expected to be inserted into the working memory with the amount field set to 5:

+ :5612.png

  1. After you have defined the GIVEN input and EXPECT results and saved all changes, click Run scenario in the upper-right corner to execute your test. If you created more tests in one file, click Run all scenarios run all the tests in a sequence.

    The test results are displayed in the Reporting panel at the bottom of the screen.

    5613.png
    Figure 3. Test Scenario Report
  2. Open the Audit log to view test scenario details.

    auditlog.png
    Figure 4. Test Scenario Audit Log
Note
Multiple Test Scenarios in One File

When you create more tests in one file, be sure to delete facts inserted by previous tests. When you insert a new GIVEN fact, notice the following fields:

  • Modify an existing fact enables you to edit a fact between knowledge base executions.

  • Delete an existing fact enables you to remove facts between executions.

    Modify and Delete and existing fact options for JBoss BRMS Test Scenarios
    Figure 5. Modifying and Deleting Existing Facts

In addition to the basic data required to create and run a test scenario, you can also perform any of the following more advanced configurations with your test scenarios:

A CALL METHOD enables you to call a method on an existing fact in the beginning of the rule execution.

Procedure
  1. Click 6176.png next to the CALL METHOD label, select an existing fact, and click Add.

    6175.png
    Figure 6. Call Method
  2. Click 6187.png and select the method to invoke from the drop-down list.

    6188.png
    Figure 7. Invoke a Method

Globals are named objects that are visible to the rule engine but are different from the objects for facts. Accordingly, the changes in the object of a global do not trigger the re-evaluation of rules. You can use and validate global fields in a test scenario.

Procedure
  1. Go to AuthoringProject Authoring and click the project name.

  2. Click Add AssetGlobal Variable(s) to create a global definition.

  3. Define your global variable name and type.

  4. Go to your test scenario, click Data ObjectsNew item to import the object type for your global in your test. If you do not import the type of your global variable, the variable will not be accessible for your test.

  5. In the Editor tab, click 6176.png next to the (globals) label, select the global, and click Add.

    New Global pop up dialog for JBoss BRMS Test Scenario feature.
  6. Click Save to save your changes.

Adding restrictions on fields is similar to adding fields and restrictions in the GIVEN section. For details, see [test_scenarios_advanced_proc].

The (configuration) label enables you to set additional constraints on the firing of rules.

Procedure
  1. Next to (configurations), select from the following drop-down options:

    • Allow these rules to fire: Select this option to specify which rules are allowed to fire for the test scenario.

    • Prevent these rules from firing: Select this option to prevent certain rules from firing for the test scenario.

    • All rules may fire: Select this option to allow all the rules to fire for the test scenario.

    Configuration rules option for JBoss BRMS Test Scenario features
    Figure 8. Configuration
  2. If you selected to allow or prevent certain rules, click 6176.png next to the empty field to select which rules are affected by the condition.

  3. Choose a rule from the drop-down list and click OK.

    Configuration select rule options for the JBoss BRMS Test Scenario feature.
    Figure 9. Selecting rules

    The selected rules will appear in the field next to the rules configuration option.

  4. Click Save to save your changes.

Next to the EXPECT section, you can configure the test scenario to use a real date and time when running the scenario, or a simulated date and time, such as if the date and time are part of what is being tested in the scenario (example: a test scenario designed for after-hours deployment).

Procedure
  1. Select Use real date and time or Use a simulated date and time to determine the time used when running the test scenario.

    Use real date and time choice for the Expect feature in JBoss BRMS Test Scenarios
    Figure 10. Real Date and Time
    Simulated date and time for Test Scenarios in JBoss BRMS 6.0.2
    Figure 11. Simulated Data and Time
  2. If you selected the simulated option, specify the year, month, day, hour, and minute associated with the test scenario.

  3. Click Save to save your changes.

After you have defined a GIVEN input fact, you can further define it by adding a literal value, bound variable, or a new fact.

Prerequisite
Procedure
  1. Within the GIVEN fact, click Add a field and add a property for your object.

  2. Click 6191.png next to the added property.

  3. Select one of the following types of field values:

    • Literal value: Creates an open field in which you enter a specific literal value.

    • Bound variable Sets the value of the field to the fact bound to a selected variable. The field type must match the bound variable type.

    • Create new fact Enables you to create a new fact and assign it as a field value of the parent fact. Click on the fact to be assigned as a field value to be supplied with a drop down of various field values. These values may be given further field values.

    Advanced Fact Data options for JBoss BRMS Test Scenarios.
    Figure 12. Advanced Options

    For example, consider this literal value field set to true:

    5607.png

    This example is equivalent to the following fact definition:

    Customer fact1 = new Customer();
    fact1.setHasInternetService(true);
    insert(fact1);

You can include additional sets of GIVEN, EXPECT, and CALL METHOD sections to your test scenario editor for more complex scenarios.

Procedure
  1. Click More below the EXPECT section. This opens a block with all three sections that can be removed by clicking 6209.png .

  2. Add data to the new set of fields as needed. For details, see [test-scenarios-create-proc].