Вы находитесь на странице: 1из 19

Oracle BPM 11g P6 Workshop

10

Business Rules

Table of Contents
10 Business Rules ................................................................................................... 1
10.1

Objective .................................................................................................. 1

10.2

Use Case Description .............................................................................. 1

10.2.1 Overview ............................................................................................. 1


10.3

Exercise Instructions ................................................................................ 2

10.3.2 Writing a test function ....................................................................... 13


10.3.3 Testing with Test Suites .................................................................... 15
10.4

Running and Testing the application ..................................................... 19

10.5

Quick Build Instructions ......................................................................... 19

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

create a rule dictionary

create a decision table

create a test function and use it to test your rule

create a test suite and use it to test your rule

10.2 Use Case Description


Note: The solution for this exercise can be found in
ps6workshop\solutions\OBR_Solution.zip

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

Process Communication Exercise 10.1


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

10.3 Exercise Instructions


Follow these instructions to complete the exercise.
Using JDeveloper, you first create a new composite application and
then you add a rule dictionary and build the rules.
1.
Create a new BPM application named NewEmployeeHireApp.
You do not need a process.
2.
Locate the artifacts that you will need from the folder in the
training materials (wherever you have unzipped the course materials).
ps6workshop\artifacts\xml\NewEmployeeHire.xsd

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.

Double-click on the NewHireDecision rule component.

10.3 Business Rules

Page 2 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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.

Functions here are the system generated rule functions that


the rules can call. You can write your own functions too.

Globals these are static or variable values that you create


which can be used in rules and functions.

BucketSets here you create sets of values or ranges of


values to use in rule design.

Links your dictionary can link to other dictionaries.

Decision Functions this is where you define how your rule is


called from a service endpoint.

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

Create a List of Values Bucketset and name it Department.


Process Communication Exercise 10.3
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

11.

Change the Data Type to int.

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.

Click OK and Save All

The next step is to decide on the outcomes for the different


combinations of values. Here are some suggested values. You will
refer frequently to this table while building the rules so note the page
number.
Green

Purple

Yellow

Error (<10)

Error

Error

Error

Low

Manual

Approve

Approve

Medium

Approve

Approve

Manual

High

Approve

Manual

Reject

>= Threshold

Manual

Reject

Reject

10.3 Business Rules

Page 4 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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.

In the Add drop down, select Condition.

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

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

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.

10.3 Business Rules

Page 6 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

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.

Add a second rule using the Add drop down menu.

10.3 Business Rules

Page 8 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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.

Add another rule.

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.

Add another rule.

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

Select Save All. Your table should look like this.

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

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

10.3 Business Rules

Page 10 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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

Add the remaining rules and actions.

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

66.
67.

Testing the rules

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.

Conflicts and Gaps

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.

10.3 Business Rules

Page 12 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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.

The decision table now looks like this.

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

Writing a test function


Your ruleset is called by the Decision Function that was automatically created
when you created your dictionary.
3. Click the Decision Functions tab in the left side of the rule editor, select the
NewHireDecision_DecisionService_1 and click the pencil icon. Look at each of
the four tabs in the dialog: Inputs, Initial Actions, Outputs, and Rulesets &
Decision Functions.

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

Create a new object of input type

Assign input values for the test

Call the Decision Function with the result going to a new object of type
List

Assign the List element to a new object of output type

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

Examine the result returning true if the expected result is returned.

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.

A template for the expression is provided.

7.

Complete the expression to create your input object.

8.

Complete the function as shown:

10.3 Business Rules

Page 14 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

This function sets department to 1 (Green) and salary to Threshold.


Threshold The rule
says that under these conditions, the response is Manual so the function returns
true if the response equals Manual.
In this test function, there is a print statement to print the output value. This is
helpful information as your test your rules.
Now you can run your function. With the function select
selected
ed in the Functions
list, click the Test button. A dialog opens with the test results.
9.

10. Change the if expression with the string Error instead of Manual and run

the function again.


Although this is a simple example and tests only one case, you can see how it
can be expanded to test them all. However, instead of doing that here, you can
use the Test Suite feature instead.

10.3.3

Testing with Test Suites


The Test Suite feature is similar to the test function you just wrote in that you set
input values and test against output values. But, instead of writing the function
using the rules language, you enter input and output values in an XML file and
use that as input to the test suite feature.
To start, create the input and output schema to match your input and output
ou
facts.
11. Click the Decision Function tab and click the Generate Test Suite

Schemas button. In the Application Navigator,, note the schema Types and
TestSuite XSD files are created in the testsuites folder.

Page 15 of 19

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

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

folder. Open the TestHireDecision.xml file.


15. The XML file can contain multiple test cases. Start by creating shells for
three cases.

<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.

Oracle BPM 11g P6 Workshop

<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.

17. Locate that namespace in the schema header

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

Process Communication Exercise 10.3


Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g PS6 Workshop

</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.

10.3 Business Rules

Page 18 of 19
Oracle Confidential. For authorized use only. Do not distribute to third parties.

Oracle BPM 11g P6 Workshop

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.

Note: The solution for this exercise can be found in


c:\obr_deepdive\Solutions\00_Solution_OBRPrerequisite.zip

1.

Asdfasfd

2.

Asdf

3.

Aadfas

4.

10.4 Running and Testing the application


Instructions for running and/or testing the completed lab

10.5 Quick Build Instructions


If possible/needed add quick build instructions

Page 19 of 19

Process Communication Exercise 10.4


Oracle Confidential. For authorized use only. Do not distribute to third parties.