Create an actual SalesModel business rule

Source: Internet
Author: User

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:

 

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.