1. Create a Java Project in Eclipse named SalesModel
2. Create a src package named org. sample in this project and create a Sales JavaBean under this directory. The source code is as follows:
PackageOrg. sample; ImportJava. util. Date; Public ClassSales { PrivateString name; Private LongSales; PrivateDate dateOfSale; Private BooleanChocolateOnlyCustomer; PublicString getName (){ ReturnName; } Public VoidSetName (String name ){ This. Name = name; } Public LongGetSales (){ ReturnSales; } Public VoidSetSales (LongSales ){ This. Sales = sales; } PublicDate getDateOfSale (){ ReturnDateOfSale; } Public VoidSetDateOfSale (Date dateOfSale ){ This. DateOfSale = dateOfSale; } Public BooleanIsChocolateOnlyCustomer (){ ReturnChocolateOnlyCustomer; } Public VoidSetChocolateOnlyCustomer (BooleanChoclateOnlyCustomer ){ This.ChocolateOnlyCustomer=ChocolateOnlyCustomer; } } |
3. Right-click the SaleModel project name and choose "Export"> "JAR file" to Export it to the specified directory.
4. Create a New packege in Guvnor and name it com. sample:
5. Click knowledgeBase-> create New-> Upload POJO Model jar. In the displayed dialog box, enter the name, as shown below:
6. Import the Jar package exported in Eclipse and click "Upload" to Upload it:
7. after successfully importing Jar, click com. sample package, you can see that org. sample. sales JavaBean (also called Model in Drools) can be used to create business rules, as shown below:
8. Create a New Business Rule named DiscountRule as follows:
9. Edit the business rule as follows:
10. This business rule is generated in a wizard-type graphical manner. After being proficient, we can directly select the technical rule-text editor mode and directly edit the source code of the Business rule using text. You can click "view source" to view the source code of the business rule:
11. After a business rule is successfully created, we create another test script for testing:
12. Click the green + sign in front of "GIVEN", insert a Fact, reference the rule as DiscountRule, and set sales = 200, name = "Acme Corp ". Insert the EXPECTed result in "EXPECTed" and click "save changes" to save the result. As follows:
13. Click "Run scenario" to Run the test case. This is similar to the JUnit unit test in Java. If the execution is normal, the result is as follows: