Skip Headers
Oracle® Fusion Middleware User's Guide for Oracle Business Rules
11g Release 1 (11.1.1.4.0)

Part Number E10228-05
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

8 Testing Business Rules

You can test your rules and Decision Tables from Rules Designer by creating an Oracle Business Rules Function. In an SOA application or in an application that accesses Oracle Business Rules with a decision function with a web service, you can test the rules at runtime with Oracle Enterprise Manager Fusion Middleware Control Console using the Test function.

This chapter includes the following sections:

8.1 Testing Oracle Business Rules at Design Time

You can define a test function to run without deploying an application. This allows you to call a decision function at runtime and to test data model elements and rulesets.

8.1.1 How to Test Rules Using a Test Function in Rules Designer

You can use Oracle Business Rules Functions to test rules from within Rules Designer. The Test Function icon is active only for functions that take no parameters and return boolean. In the body of the function you create input facts, call a decision function, and check the output to validate the facts the decision function returns are as expected.

To enable logging you call RL.watch.all(). To run the function you click the Test Function icon in the Functions table.

For more information about functions, see Section 2.5, "Working with Oracle Business Rules Functions".

To test rules using a test function:

  1. Confirm that your dictionary is valid.

    For more information on dictionary validation, see Section 4.4.4, "How to Validate a Dictionary".

  2. In Rules Designer, select the Functions navigation tab.

  3. In the Functions area click Create....

  4. Enter the function name in the Name field, or use the default name.

  5. Select the return type from the Return Type list.

    For a test function, select boolean.

  6. In the Arguments table, confirm that there are no arguments. For a test function, you cannot specify any arguments.

  7. In the Body area, enter the test function body.

    In the body of the function you can call a decision function using assign new to call and get the return value of the decision function. Thus, to test a decision function you create the input data and call the decision function.

    Example 8-1 shows a simple test function that calls print. Figure 8-1 shows the test function definition. For information on adding a test function that calls a decision function, see Section 8.1.3, "How to Test a Decision Function Using an Oracle Business Rules Function".

    Example 8-1 Test Function Body

    call print("Hello World")
    return true
    

    Figure 8-1 Adding a Test Function

    Description of Figure 8-1 follows
    Description of "Figure 8-1 Adding a Test Function"

  8. In the Functions table select the function and click the Test Function icon.

    The output is displayed in a Function Test Result dialog, as Figure 8-2 shows.

    Figure 8-2 Test Function Results Dialog

    Description of Figure 8-2 follows
    Description of "Figure 8-2 Test Function Results Dialog"

  9. Click OK to dismiss the Function Test Result dialog.

8.1.2 What You Need to Know About Testing Using an Oracle Business Rules Function

The Test Function icon is only active when the dictionary is valid (the Business Rule validation log is empty). The Test Function icon is gray if the dictionary associated with the function contains any validation warnings.

8.1.3 How to Test a Decision Function Using an Oracle Business Rules Function

You can test rulesets by creating a decision function and calling the decision function from Rules Designer with an Oracle Business Rules function. In the body of the Oracle Business Rules function you create input facts, call a decision function, and validate the facts output from the decision function. For more information, see Section 6.1, "Introduction to Decision Functions" and Section 2.5, "Working with Oracle Business Rules Functions".

To test a decision function using an Oracle Business Rules function:

  1. Confirm that your dictionary is valid.

    For more information on dictionary validation, see Section 4.4.4, "How to Validate a Dictionary"

  2. In Rules Designer, select the Functions navigation tab.

  3. In the Functions area click the Create... icon.

  4. Enter the function name in the Name field, or use the default name.

  5. Select the return type from the Return Type list.

    For a test function, select boolean.

  6. In the Arguments table, confirm that there are no arguments. For a test function, you cannot specify any arguments.

  7. In the Body area, enter the test function body.

    In the body of the test function you can call a decision function using assign new to call and get the return value of the decision function (in the body of the test function you create input facts, call a decision function, and validate the facts output from the decision function).

    A decision function call returns a List. Thus, to test a decision function in a test function you do the following:

    • You create the input data as required for the decision function input arguments.

    • You call the decision function with the arguments you create in the test function.

    • You place results in a List, for example, in the following:

      assign new List resultsList = DecisionFunction_1(testScore)
      

    Figure 8-3 shows a test function that calls a decision function.

    Figure 8-3 Test Function to Call a Decision Function that Returns a List

    Description of Figure 8-3 follows
    Description of "Figure 8-3 Test Function to Call a Decision Function that Returns a List"

  8. Select the function and click the Test Function icon.

    The function is executed. The output is shown in a Function Test Result dialog, as Figure 8-4 shows.

    Figure 8-4 Test Function Results for Grade Test

    Description of Figure 8-4 follows
    Description of "Figure 8-4 Test Function Results for Grade Test"

  9. Click OK to dismiss the Function Test Result dialog.

8.1.4 What You Need to Know About Testing Decision Functions

You can use Oracle Business Rules Functions to test decision functions from within Rules Designer. Keep the following points in mind when using a test function:

  • The Test Function icon is gray if the dictionary associated with the test Oracle Business Rules Function contains any validation warnings. The Test Function icon is only shown when the dictionary validates without warnings.

  • To enable logging you can call RL.watch.all(). For more information on RL Language functions, see Oracle Fusion Middleware Language Reference Guide for Oracle Business Rules. In this guide, RL.watch.all() is an alias for the RL Language function watchAll().

  • As an alternative to the example shown in Figure 8-3, you can enter the function body that is shown in Example 8-2. This function runs and shows the RL.watch.all() output. The dialog shows "Test Passed" when the grade is in the B range as shown in Figure 8-5. The dialog shows "Test Failed" when the grade asserted is not in the B range, as shown in Figure 8-6.

    Example 8-2 Function Body with True or False Return Value

    call RL.watch.all()
    assign new TestScore testScore = new TestScore()
    modify (testScore, name: "Bill Reynolds", testName: "Math Test", testScore: 81)
    assign new TestGrade testGrade = (TestGrade)DecisionFunction_1(testScore).get(0)
    return testGrade.grade == Grade.B
    

    For the testScore value 81, this function returns "Test Passed" as shown in Figure 8-5. For the testScore value 91, this returns "Test Failed", as shown in Figure 8-6.

    Figure 8-5 Test Passed Test Function Output

    Description of Figure 8-5 follows
    Description of "Figure 8-5 Test Passed Test Function Output"

    Figure 8-6 Test Failed Test Function Output

    Description of Figure 8-6 follows
    Description of "Figure 8-6 Test Failed Test Function Output"

8.2 Testing Oracle Business Rules at Runtime

In an SOA application that uses Oracle Business Rules with a Decision Service you can test rules at runtime with Oracle Enterprise Manager Fusion Middleware Control Console Test function.

For more information on using the Test function, see Oracle Fusion Middleware Administrator's Guide for Oracle SOA Suite and Oracle Business Process Management Suite .