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"));
}
Aggregations