use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class InaccurateComparisonTest method testStringCoercionComparison.
@Test
public void testStringCoercionComparison() {
final String rule = "package " + TestConstants.PACKAGE_REGRESSION + "\n" + " import " + TestConstants.PACKAGE_TESTCOVERAGE_MODEL + ".Message;\n" + " rule \"string coercion\" \n" + " when\n" + " m : Message( message < \"90201304122000000000000017\" )\n" + " then \n" + " end";
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModuleFromDrl(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, rule);
KieSession ksession = kieBase.newKieSession();
ksession.insert(new Message("90201304122000000000000015"));
Assertions.assertThat(ksession.fireAllRules()).isEqualTo(1);
}
use of org.drools.testcoverage.common.model.Message 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"));
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorStartsWithOOPath.
@Test
public void testTemporalOperatorStartsWithOOPath() {
final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + "global java.util.List events\n" + "global java.util.List messages\n" + "\n" + "declare org.drools.testcoverage.common.model.MessageEvent\n" + " @role( event )\n" + " @duration( duration )\n" + "end\n" + "rule R when\n" + " ev1: MessageEvent( /msg[ message == 'Ping' ] )\n" + " ev2: MessageEvent( $message: /msg[ message == 'Pong' ], this starts[ 1s ] ev1 )\n" + "then\n" + " messages.add( $message );\n" + "end\n";
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModuleFromDrl(MODULE_GROUP_ID, kieBaseTestConfiguration, drl);
this.initKieSessionWithPseudoClock(kieBase);
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS));
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), DEFAULT_DURATION_IN_SECS));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The first sequence of events should NOT make the rule fire").isEmpty();
final Message pongMessage = this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS - 1000));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorIncludesWithOOPath.
@Test
public void testTemporalOperatorIncludesWithOOPath() {
final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + "global java.util.List events\n" + "global java.util.List messages\n" + "\n" + "declare org.drools.testcoverage.common.model.MessageEvent\n" + " @role( event )\n" + " @duration( duration )\n" + "end\n" + "rule R when\n" + " ev1: MessageEvent( /msg[ message == 'Ping' ] )\n" + " ev2: MessageEvent( $message: /msg[ message == 'Pong' ], this includes ev1 )\n" + "then\n" + " messages.add( $message );\n" + "end\n";
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModuleFromDrl(MODULE_GROUP_ID, kieBaseTestConfiguration, drl);
final SessionPseudoClock clock = this.initKieSessionWithPseudoClock(kieBase);
final Message pongMessage = this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS), clock, 1);
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS - 1500));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The first sequence of events should NOT make the rule fire").isEmpty();
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), DEFAULT_DURATION_IN_SECS - 1500));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorDuringWithOOPath.
@Test
public void testTemporalOperatorDuringWithOOPath() {
final String drl = "import org.drools.testcoverage.common.model.Message;\n" + "import org.drools.testcoverage.common.model.MessageEvent;\n" + "global java.util.List events\n" + "global java.util.List messages\n" + "\n" + "declare org.drools.testcoverage.common.model.MessageEvent\n" + " @role( event )\n" + " @duration( duration )\n" + "end\n" + "rule R when\n" + " ev1: MessageEvent( /msg[ message == 'Ping' ] )\n" + " ev2: MessageEvent( $message: /msg[ message == 'Pong' ], this during ev1 )\n" + "then\n" + " messages.add( $message );\n" + "end\n";
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModuleFromDrl(MODULE_GROUP_ID, kieBaseTestConfiguration, drl);
final SessionPseudoClock clock = this.initKieSessionWithPseudoClock(kieBase);
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), DEFAULT_DURATION_IN_SECS));
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS), clock, 1);
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The first sequence of events should NOT make the rule fire").isEmpty();
final Message pongMessage = this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS - 1500));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
Aggregations