Create an actual salesmodel business rule

Source: Internet
Author: User

1. Create a Java Project in eclipse named SalesModel

2. In the project, create a src package named Org.sample, under which a sales JavaBean is created, with the following source code:

Package org.sample;

import java.util.Date;

Public class Sales {

Private String name;

Private long sales;

Private Date Dateofsale;

Private boolean Chocolateonlycustomer;

Public String GetName () {

return name;

}

Public void setName (String name) {

this. Name = name;

}

Public long getsales () {

return sales;

}

Public void setsales (long sales) {

this. Sales = sales;

}

Public Date Getdateofsale () {

return Dateofsale;

}

Public void Setdateofsale (Date dateofsale) {

this. Dateofsale = Dateofsale;

}

Public boolean Ischocolateonlycustomer () {

return Chocolateonlycustomer;

}

Public void Setchocolateonlycustomer (boolean choclateonlycustomer) {

this. Chocolateonlycustomer = Chocolateonlycustomer;

}

}

3. Then right-click on the Salemodel project name and select "Export", "JAR file" to export to the specified directory. 4. Next, create a new packege in Guvnor named Com.sample:

5. Click the knowledgebase->create new->upload POJO Model jar and enter the name in the popup dialog box as follows:

6. Import the jar file package exported above in Eclipse and click "Upload" to upload:

7. After importing the jar successfully, click on the left Com.sample package and you can see that the Org.sample.Sales JavaBean has appeared in the configuration item (also called model in drools). You can then use the model to create a business rule, as follows:

8. Create a new business rule, named Discountrule, as follows:

9. Edit the business rule as follows:

10. The business rules are generated in a wizard-style graphical way, we can directly choose Technical Rule–text Editor mode, directly edit the business rule source code with text. You can view the source code for a business rule by tapping View Source:

11. Once a business rule has been successfully created, we create a test script to validate it:

12. Click the green + sign in front of "GIVEN", insert a fact, reference the rule to Discountrule, and set sales=200,name= "Acme Corp". Then insert the desired result in "expected" and click "Save Changes" to save. As shown below:

13. Click "Run Scenario" to run the test case, which is similar to the JUnit unit test in Java, and if it does, the result is as follows:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.