Search in sources :

Example 1 with Customer

use of org.drools.testcoverage.common.model.Customer in project drools by kiegroup.

the class RuleTemplateTest method testGuidedRuleTemplate.

@Test
public void testGuidedRuleTemplate() throws Exception {
    final String resourceName = "cheese.template";
    final KieResources kieResources = KieServices.get().getResources();
    final Resource resource = kieResources.newClassPathResource(resourceName, RuleTemplateTest.class);
    resource.setResourceType(ResourceType.TEMPLATE);
    final KieBase kBase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource);
    final KieSession kSession = kBase.newKieSession();
    final Cheese cheese = new Cheese();
    cheese.setPrice(90);
    final Customer petr = new Customer(0, "Peter");
    final Customer john = new Customer(1, "John");
    kSession.insert(cheese);
    kSession.insert(petr);
    kSession.insert(john);
    Assertions.assertThat(kSession.fireAllRules()).as("One rule should be fired").isEqualTo(1);
    final Collection messages = kSession.getObjects(object -> object instanceof Message);
    Assertions.assertThat(messages).hasSize(1);
    Assertions.assertThat(messages).hasOnlyOneElementSatisfying(message -> ((Message) message).getMessage().compareTo("Peter satisfied"));
}
Also used : Message(org.drools.testcoverage.common.model.Message) Customer(org.drools.testcoverage.common.model.Customer) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.testcoverage.common.model.Cheese) KieResources(org.kie.api.io.KieResources) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)1 Cheese (org.drools.testcoverage.common.model.Cheese)1 Customer (org.drools.testcoverage.common.model.Customer)1 Message (org.drools.testcoverage.common.model.Message)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieResources (org.kie.api.io.KieResources)1 Resource (org.kie.api.io.Resource)1 KieSession (org.kie.api.runtime.KieSession)1