7 Testing and Validating Business Rules
Test and validate the rules you have created or edited.
7.1 Overview
The business rules test feature enables both developers and business users to quickly check that a rule satisfies the expected behavior or, if modified, to see if a rule regresses existing functionality.
You can author and test rules at design-time in Oracle JDeveloper or Business Process Composer. At runtime, you can test rules in SOA Composer.
You can write tests declaratively, with no need for knowledge of XML or prior rules actions or programming languages such as Java. Additionally, tests support all types of facts (XML, Java, RL, and ADF-BC) and can be run on SOA or non-SOA use cases.
The test feature provides test reports with diagnostic comments and visual differences between the expected and actual values that can be used to correct the rules or fix the tests.
Figure 7-1 shows the UI in JDeveloper. For more information about using JDeveloper, see Introduction to Oracle JDeveloper in Oracle Fusion Middleware Developing Applications with Oracle JDeveloper.
7.1.1 Components of the Test Feature
No matter which UI you use, the testing functionality behaves mostly the same way in JDeveloper, BP Composer, and SOA Composer.
Decision functions must have been already created before you begin--there is a one to one mapping between decision functions and tests. Once a decision function is associated with a test suite or test template, it cannot be changed later.
The components of the test feature are:
-
Test Suites and Test Cases
You can create a test suite with one or more test cases. You can also create templates that serve as templates for creating other test cases.
-
Test Templates
Test templates enable you to create similar test cases that differ only by the values of a few Fact properties. Templates also let you execute ad-hoc tests by specifying values for parameters. Ad-hoc tests enable you to perform sanity tests and try different value combinations for specific parameters before creating them as test cases in a test suite.
-
Test Execution
Executing test suites or test cases invokes the decision function and executes the rulesets defined in the decision function and presents the results in a new tab, as shown in Figure 7-2. Tests are executed via RL generation.
Keep the following in mind:
-
Tests can be executed either from the Test tab of the Dictionary or from the Decision Functions tab.
-
Tests can be defined in the current dictionary for decision functions in linked dictionaries.
-
Tests defined in linked dictionaries can be executed in the current dictionary. Tests from linked dictionaries are available as read-only for execution.
-
If you modify the inputs/outputs in a decision function, the changes are automatically synced to the tests you have defined. Tests are synced to fact-types referenced in the tests. If you remove facts from a decision function, the test feature enables you to delete those facts from the input/output tree of the test.
-
A Fact is an instance of a FactType that defines the Test Data and has property values corresponding to each of the FactType properties. If a Property value is a complex data type, it is defined using Fact instances as well.
-
7.2 Testing Rules in JDeveloper
You can test your rules as you design them in JDeveloper.
In the Test Case editor, you define the inputs and expected output values for a Test Case. The values here can be simple values or expressions that use globals, functions, and so on.
The input and output Fact trees are auto-initialized based on the inputs/outputs specified for the Decision Function.
The test input and output Fact trees are also auto-synchronized with any changes to the Decision Function (if you add, delete, modify inputs or outputs) or fact types (if you add, delete or modify properties). The auto-synchronization flags and highlights invalid Facts or Property values that were changed in a Decision Function or Fact type. These flags in the test input/output help you to identify and fix issues in your test definitions.
Testing Permission Related Cases
Before testing permission related cases, change the refresh time 10 seconds. This is an important prerequisite for reliable test results.
To change the refresh time to 10 seconds:
-
Navigate to
$MW_HOME/user_projects/domains/soainfra/config/fmwconfig
. -
Open
jps-config.xml
. -
Set
oracle.security.jps.ldap.policystore.refresh.interval
to 10000.<serviceInstance name="pdp.service" provider="pdp.service.provider"> <property name="oracle.security.jps.ldap.policystore.refresh.interval" value="10000"/> </serviceInstance>
-
Restart the server.
7.2.1 How to Create and Manage Test Suites and Cases
You can create a test suite with one or more test cases. Test suites can only be defined for specific decision functions.
For more information about decision functions, see Working with Decision Functions.
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To create a test suite:
When you have finished creating test suites and cases, you can run them. For more information, see How to Run Test Suites or Cases.
7.2.2 How to Create Test Templates
Test templates enable you to reuse input and output values to repeat tests on those fields and values.
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To create a test template:
When you have finished setting up your test templates, you can run them. For more information, see How to Run Ad-hoc Tests from Test Templates.
7.2.3 How to Run Test Suites or Cases
When you run a test, a new tab is opened, and you can see the diagnostic comments, exceptions, and test results. Tests can be run either as a suite, multiple test cases, or as individual test cases.
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To run a test suite or case:
The execute button is enabled only when a test suite or test case (or test template) is selected from the table and as long as there are no validation warnings in the current dictionary.
7.2.4 How to Run Ad-hoc Tests from Test Templates
This is where you can run ad-hoc tests from templates by editing the nodes in input and output trees. The inputs and outputs are from the decision function.
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To run ad-hoc tests from test templates:
7.2.5 How to Run Tests for a Specific Decision Function
You can run tests from the Decision Function tab. This view only shows you the Test Suites and Test Cases for the specific Decision Function.
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To run tests for a specific decision function:
- In Rules Designer, click the Decision Functions tab.
- Click to select a test case and click the Test button.
- The Decision Function Test Editor dialog appears. This dialog is just another view of the testing feature.
7.3 Testing Rules in Business Process Composer
You can test your rules as you design them in Business Process Composer.
For more information about using Business Process Composer, see Introduction to Oracle Business Process Composer in Oracle Fusion Middleware Developing Business Processes with Oracle Business Process Composer.
7.4 Testing Rules in SOA Composer
At runtime, you can use SOA Composer to regression test rules. This enables business users to quickly check if a modified rule changes the existing functionality.
Figure 7-7 shows the Tests tab in SOA Composer. The Tests tab only appears if you have a deployed composite and are in a SOA Composer session. Click Create Session to open a session.
7.4.1 How to Create and Manage Test Suites and Cases
You can create a test suite with one or more test cases. Test suites can only be defined for specific decision functions.
For more information about decision functions, see Working with Decision Functions.
For detailed documentation of fields and other UI controls, click Help, Help for This Page from within SOA Composer.
To manage test suites and cases:
When you have finished setting up your test suites and cases, you can run them. For more information, see How to Run Test Suites or Cases.
7.4.2 How to Create Test Templates
Test templates enable you to reuse input and output values to repeat tests on those fields and values.
For detailed documentation of fields and other UI controls, click Help, Help for This Page from within SOA Composer.
To create test templates:
- In Rules Designer, click the Tests tab.
- Click Test Model in the navigation tree. In the Test Templates region, click + to create a new test template.
- Enter a Name, Description, and choose a Decision Function.
- Click Save.
To run ad-hoc tests from test templates, see How to Run Ad-hoc Tests from Test Templates.
7.4.3 How to Run Test Suites or Cases
When you run a test, a new tab is opened, and you can see the diagnostic comments, exceptions and test results. Tests can be run either as a suite, multiple test cases or as individual test cases. Tests are executed via RL generation.
For detailed documentation of fields and other UI controls, click Help, Help for This Page from within SOA Composer.
To run test suites or cases:
Figure 7-10 Diagnostic Comments for a Test Suite

Description of "Figure 7-10 Diagnostic Comments for a Test Suite"
If you select a test suite from the Test Model tree and run it, you can see the Decision Trace tab, as shown in Figure 7-11.
7.4.4 How to Run Ad-hoc Tests from Test Templates
The Input and Output trees are loaded with input and output facts from the associated Decision Function, as shown in Figure 7-12. If you modify facts in a Decision Function, those changes are automatically synced to the Input and Output facts.
For detailed documentation of fields and other UI controls, click Help, Help for This Page from within SOA Composer.
To run ad-hoc tests from test templates:
7.4.5 How to Run Tests for a Specific Decision Function
You can run tests for specific Decision Functions, as shown in Figure 7-13:
For detailed documentation of fields and other UI controls, click Help from within JDeveloper.
To run tests for a specific Decision Function:
- Click the Decision Functions tab and select the appropriate Decision Function from the list.
- In the Tests field, use the dropdown to select the appropriate test.
- The test is opened in the Tests tab. Click the test, and then click Execute to run your test.
- The results tab appears. Click the new tab to view test results.
7.5 Testing Decision Functions Using a 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 Introduction to Decision Functions and Introduction to Oracle Business Rules Functions.
To test a decision function using an Oracle Business Rules function:
7.5.1 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 button is gray if the dictionary associated with the test Oracle Business Rules Function contains any validation warnings. The Test Function button 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 Rules Language Reference for Oracle Business Process Management. In this guide,RL.watch.all()
is an alias for the RL Language functionwatchAll()
. -
As an alternative to the example above, you can enter the function body that is shown in the example below:
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
value81
, this function returns Test Passed. For thetestScore
value91
, this returns Test Failed.This function runs and shows the
RL.watch.all()
output. The dialog shows Test Passed when the grade is in the B range. The dialog shows Test Failed when the grade asserted is not in the B range.
7.6 Testing Decision Services in SOA Composites
In a BPM or 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 Web Service page, where you can create an instance of your composite for testing.
For more information about how to create a test instance of your composite after you have finished designing and deploying it, see Initiating a SOA Composite Application Test Instance in Oracle Fusion Middleware Administrating Oracle SOA Suite and Oracle Business Process Management Suite.
You can see the audit trail for the Decision Service execution. For more information, see Monitoring Business Rule Tracing in Oracle Fusion Middleware Administrating Oracle SOA Suite and Oracle Business Process Management Suite.