Professional Documents
Culture Documents
10 Business Rules: 10.1 Objective
10 Business Rules: 10.1 Objective
10
Business Rules
Table of Contents
10 Business Rules ................................................................................................... 1
10.1
Objective .................................................................................................. 1
10.2
10.5
10.1 Objective
The objective of this lab is to give you a rudimentary understanding of
Oracle Business Rules 11g release 11.1.1.7.0.
In this exercise you build a rule dictionary from scratch and test it in
various ways. This document provides step by step instructions but
you are encouraged to use the detailed steps only when necessary.
When you finish this exercise you will be able to
10.2.1
Overview
The decision service you are building takes input values for salary and
department and determines if a hire request is approved automatically,
rejected automatically, requires manual review, or if the request has an
error.
Page 1 of 19
3.
Drag a rule component onto the composite and set the name:
NewHireDecision
4.
Set Inputs/Outputs by importing the xsd named above and
choosing hireRequestInfo for input and hireResponseInfo for output.
You do not need a Composite Service endpoint for this application.
Click OK to create the new rule dictionary.
This is a good time to Save All.
Now, using JDeveloper, open the NewEmployeeHire.xsd by doubleclicking on it, and view the schema. You can view it graphically or
select the source view to view the text.
The input data includes salary and department. You use these
values in the rules to determine the decision and set the output string,
hireResult.
5.
Page 2 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
Take a look around. On the left side, starting from the top are the
following tabs:
Facts the input and output facts are here along with any
system generated facts.
RuleSets rulesets are where the rules go. There are two
types of rules, IF-THEN and Decision Table.
6.
A ruleset has been created automatically. First, change the
name of the ruleset to HireDecision by clicking on the ruleset name at
the top for the edit box to appear.
7.
Next, add a List of Ranges Bucketset called Salary for salary
ranges. Click the Add Bucket with Lower Endpoint Included (green
plus-sign) three times so that you have four buckets.
8.
Set the Endpoints for the buckets to be 100, 50, 10, and notice
the ranges are set.
9.
Edit the Alias values to be: high, medium, low, and error. Press
Enter after typing the alias to set the value.
10.
Page 3 of 19
11.
12.
Create three new values and set the alias to Green, Purple, and
Yellow. Leave the values as defaulted: 1, 2, 3. These are the
(arbitrary) departments which affect whether the requested hire salary
is approved or not.
13.
Create a Global to specify a salary threshold over which would
be an error. This could also be done with another range in the Salary
list of ranges but putting it outside of the range makes it easier to read
and manage.
14.
Name the global Threshold, type int. Using Expression
Builder set value to 200.
15.
Use the Final checkbox to indicate the value is not changed by
the rule actions.
16.
Purple
Yellow
Error (<10)
Error
Error
Error
Low
Manual
Approve
Approve
Medium
Approve
Approve
Manual
High
Approve
Manual
Reject
>= Threshold
Manual
Reject
Reject
Page 4 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
17.
There are 15 rules to write. This sort of decision is best done
with rules in a Decision Table. The column and row headings are the
conditions and the cells are the result that is set in the rule action. Now
its time to write the rules
18.
Select the HireDecision ruleset tab and then click the Create
Decision Table button. Change the name of the table to
DetermineResponse
Notice the red underline on the table and ruleset names. This
indicates there is an error in your ruleset. You can hover over the line
to see the warnings. In this case, the problem is simply that there are
no rules. Now it is time to add some rules.
First, add the conditions. One condition is the expression, salary >=
threshold and for the rest of the outcomes, test against the salary and
department value.
19.
20.
21.
Double-click the <edit-condition> text and a menu of choices
opens. In this case, you want to write an expression so select the
Expression Builder button.
Page 5 of 19
22.
23.
In the Expression Builder, select hireRequestInfo.salary and
click the Insert Into Expression button.
24.
25.
26.
Complete the expression by typing in >= and adding Threshold
from the Constants tab.
Page 6 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
27.
28.
Click OK.
29.
Add two more conditions and set one to hireRequestInfo.salary
and the other to hireRequestInfo.department.
30.
31.
As soon as you have added a condition, a rule column is also
added called R1. Set the cell values in this rule to match the first of the
>= Threshold cells in the table of rules created earlier.
32.
Click the ? in the first cell under R1 to set the condition value
This cell is called C1 R1 (condition 1, rule 1). Notice your choices are
constrained to true and false. The rule editor recognizes your Boolean
expression and constrains the options automatically. Select true and
click OK.
33.
34.
Page 7 of 19
35.
Set the value for C2 R1 to dont care by setting the checkbox,
Specify Value as Dont Care.
36.
37.
When you have a cell selected, a menu button appears above
the condition list showing how the values for this cell are constrained.
Notice how the menu changes when you select the different cells.
38.
You can use the bucketsets you created earlier to constrain the
values in the cells for salary and department.
39.
Select C2 R1 and then click the menu and select Salary from
the list.
40.
41.
Select C3 R1 and constrain the values to the Department
bucketset.
42.
Now, set the value for C3 R1 to Green. This is the first of your
15 rules.
43.
44.
Page 8 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
45.
New rules always are added at the beginning and then moved
automatically as you add condition values to combine with related rules
already present. The rule column names dont change so the first rule
is always R1.
46.
For the C1 R1 cell, enter true. For C2 R1, enter dont care.
For C3 R1, enter the Purple, Yellow. This is for the second and third of
your 15 rules.
47.
Notice how the columns merge automatically for like values and
then the rules change places to be in sort-order.
48.
49.
50.
This rule covers the Error case which is actually 3 of your 15
rules from the earlier table. In this order, set C2 R1 to Error and set C3
R1 and C1 R1 to dont care.
51.
52.
Set salary to low, department to Green and Threshold
expression to dont care.
53.
In the next rule, set salary to low, department to Purple, Yellow,
and Threshold expression to dont care.
54.
Page 9 of 19
55.
56.
Before going further, set the rule actions for the 5 rules entered
already.
57.
Double-click <insert action> in the Actions section and select
assert new. Then, double-click on the assert new and in the Actions
Editor, select hireResponseInfo and select the checkbox for
Parameterized so that different values can be set for each rule.
58.
59.
Click OK.
60.
For each action in the rule columns, set the checkbox and enter
the response value for each rule. Refer to the table as necessary. For
Page 10 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
now, ignore the conflict warnings. Your decision table should look like
this.
61.
62.
The rule editor warns you when a rule conflicts with another
rule. This is when multiple rules may fire when these conditions are
met. You can set conflict overrides everywhere but that can get
confusing. Its better to let the rule editor help you write correct rules.
63.
Take a look at the conflicts for R3 the editor is telling you that
R1 and R2 will also fire under these conditions. This is because the
Threshold expression is dont care. The salary value for R1 and R2 is
also dont care. Therefore, when the Threshold expression is true or
false and the salary is any value, R1, R2, and R3 are all true.
64.
Change the Threshold value for R3 from dont care to false.
The conflicts go away because the rules are more specific and no
longer overlap
65.
Page 11 of 19
66.
67.
68.
Now it is time to test your rules. There are built-in test features
for rule conflicts and for testing for gaps in selected input ranges. You
can also write your own tests.
69.
70.
First, you already know there are no conflicts. Next test for
gaps in the input ranges you selected in the rules.
71.
On the tool bar test for gaps by clicking the Gap Analysis icon
(magnifying glass over the table icon).
A dialog opens showing there is a gap resulting in four missing condition
combinations. The rules for those combinations can be added from the dialog.
Instead, adding a rule for otherwise would fix this. Cancel the Gap Analysis
dialog and add a rule with otherwise for the department and dont care for
Threshold expression and for salary.
1.
Page 12 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
2. There is a conflict but only until you set the hireResult to Error. The conflict
goes away because R3 and R11 have the same result and it doesnt matter
which rule fires. Now when you run the gap analysis, you pass the test.
Now its time to write some unit tests. You would run unit tests whenever you
change the rules to ensure the rules still provide the expected results.
10.3.2
In this Decision Function, the one ruleset that you created is selected. This
ruleset is executed when the NewHireDecision_DecisionService_1 is called. You
can write a function that calls NewHireDecision_DecisionService_1 and examine
the result.
Functions can be called from rules but if you create a function that returns a
Boolean, you can run the function right in JDeveloper.
This type of test function has a common set of actions no matter what your rules
are like. It takes the following form:
Page 13 of 19
Call the Decision Function with the result going to a new object of type
List
4.
Click the Functions tab and click the Create button to create a new function.
5.
Call the function Test and set the Return Type to Boolean.
6. In the Body of the function, select <insert action> and from the drop down
list, select assign new.
7.
8.
Page 14 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
10. Change the if expression with the string Error instead of Manual and run
10.3.3
Schemas button. In the Application Navigator,, note the schema Types and
TestSuite XSD files are created in the testsuites folder.
Page 15 of 19
12. Click the Test button drop down and select Test With Test Suite to open the
Decision Function Test dialog.
13. In the Decision Function Test dialog, click the Create button to create a
new test suite called TestHireDecision. This creates the base XML for the input
and output values. Click Cancel.
The next step is to edit XML files for the input and output data.
14. In the testsuites folder, expand the rules folder and the NewHireDecision
<testCase name="TestHireDecision_GreenHigh">
<testInput>
</testInput>
<expectedOutput>
</expectedOutput>
</testCase>
<testCase name="TestHireDecision_GreenMed">
<testInput>
</testInput>
<expectedOutput>
</expectedOutput>
</testCase>
<testCase name="TestHireDecision_GreenLow">
<testInput>
</testInput>
10.3 Business Rules
Page 16 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
<expectedOutput>
</expectedOutput>
</testCase>
16. Next open the gener
generated
ated schema Types file to find the input and output
details and note the namespace for the two types. Here it is ns1 but yours may
be different.
18. and then find that same name in your XML file.
19. So you use, iin this case, ns2 in your data. Using the element names from
the generated Types schema and the element names in the import schema file
NewEmployeeHire.xsd, fill out the test cases. The test case schema is defined in
the generated TestSuite XSD file.
Your final XML looks like this.
<testCase name="TestHireDecision_GreenHigh">
<testInput>
<ns2:hireRequestInfo>
<ns2:requestor>test</ns2:requestor>
<ns2:employeeName>test</ns2:employeeName>
<ns2:salary>150</ns2:salary>
<ns2:department>1</ns2:department>
</ns2:hireRequestInfo>
</testInput>
<expectedOutput>
<ns2:hireResponseInfo>
<ns2:hireResult>Approve</ns2:hireResult>
</ns2:hireResponseInfo>
</expectedOutput>
</testCase>
<testCase
ase name="TestHireDecision_GreenMed">
<testInput>
<ns2:hireRequestInfo>
<ns2:requestor>test</ns2:requestor>
<ns2:employeeName>test</ns2:employeeName>
<ns2:salary>75</ns2:salary>
<ns2:department>1</ns2:department>
</ns2:hireRequestInfo>
Page 17 of 19
</testInput>
<expectedOutput>
<ns2:hireResponseInfo>
<ns2:hireResult>Approve</ns2:hireResult>
</ns2:hireResponseInfo>
</expectedOutput>
</testCase>
<testCase name="TestHireDecision_GreenLow">
<testInput>
<ns2:hireRequestInfo>
<ns2:requestor>test</ns2:requestor>
<ns2:employeeName>test</ns2:employeeName>
<ns2:salary>25</ns2:salary>
<ns2:department>1</ns2:department>
</ns2:hireRequestInfo>
</testInput>
<expectedOutput>
<ns2:hireResponseInfo>
<ns2:hireResult>Manual</ns2:hireResult>
</ns2:hireResponseInfo>
</expectedOutput>
</testCase>
20. Run this test suite by selecting Test With Test Suite from the Test drop
down menu on the Decision Function tab.
21. Select TestHireDecision in the Test Suite drop down and click Run Test.
The output of the run is displayed. If all tests pass, the output shows Passed at
the top. Then, each test case is displayed with the trace info for the test run. If a
test case fails, the comments cell shows what values were used in the test case.
Page 18 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.
If you get the error message, The test suite is invalid and cant be executed
there are a number of things to check.
Make sure your namespace is correct.
Make sure you have all elements of your input and output facts included.
The elements must be in the same order as they appear in the XSD artifact which
defines them.
You have completed the pre-requisite for the Rules Deep Dive course.
1.
Asdfasfd
2.
Asdf
3.
Aadfas
4.
Page 19 of 19