Oracle® Fusion Middleware User's Guide for Oracle Business Rules 11g Release 1 (11.1.1) Part Number E10228-02 |
|
|
View PDF |
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:
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.
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:
Confirm that your dictionary is valid.
For more information on dictionary validation, see Section 4.4.4, "How to Validate a Dictionary".
In Rules Designer, select the Functions navigation tab.
In the Functions area click Create....
Enter the function name in the Name field, or use the default name.
Select the return type from the Return Type dropdown list.
For a test function, select boolean
.
In the Arguments table, confirm that there are no arguments. For a test function, you cannot specify any arguments.
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".
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.
Click OK to dismiss the Function Test Result dialog.
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.
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:
Confirm that your dictionary is valid.
For more information on dictionary validation, see Section 4.4.4, "How to Validate a Dictionary"
In Rules Designer, select the Functions navigation tab.
In the Functions area click the Create... icon.
Enter the function name in the Name field, or use the default name.
Select the return type from the Return Type dropdown list.
For a test function, select boolean
.
In the Arguments table, confirm that there are no arguments. For a test function, you cannot specify any arguments.
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
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
Click OK to dismiss the Function Test Result dialog.
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
Figure 8-6 Test Failed Test Function Output
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.