use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class FusionAfterBeforeTest method testAfterBeforeOperators.
@Test
public void testAfterBeforeOperators() {
final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("fusionAfterBeforeTest.drl", getClass());
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
final KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.PSEUDO);
final KieSession ksession = kieBase.newKieSession(ksconf, null);
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
final EntryPoint stream = ksession.getEntryPoint("EventStream");
SessionPseudoClock clock = ksession.getSessionClock();
try {
for (int i = 0; i < 3; i++) {
final MessageEvent tc = new MessageEvent(MessageEvent.Type.received, new Message());
stream.insert(tc);
ksession.fireAllRules();
clock.advanceTime(8, TimeUnit.SECONDS);
}
ksession.fireAllRules();
} finally {
ksession.dispose();
}
Assertions.assertThat(listener.isRuleFired("AfterMessageEvent")).as("Rule 'AfterMessageEvent' was no fired!").isTrue();
Assertions.assertThat(listener.isRuleFired("BeforeMessageEvent")).as("Rule 'BeforeMessageEvent' was no fired!").isTrue();
// each rules should be fired 2 times
int firedCount = 2;
int actuallyFired = listener.ruleFiredCount("AfterMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'AfterMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
firedCount = listener.ruleFiredCount("BeforeMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'BeforeMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class GlobalOnLHSTest method testNPEOnMutableGlobal.
@Test
public void testNPEOnMutableGlobal() throws Exception {
KieSession ksession = session.getStateful();
List<String> context = new ArrayList<String>();
ksession.setGlobal("context", context);
ksession.setGlobal("LOGGER", LOGGER);
FactHandle b = ksession.insert(new Message("b"));
ksession.delete(b);
int fired = ksession.fireAllRules(1);
Assertions.assertThat(fired).isEqualTo(0);
ksession.dispose();
}
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.getKieBaseFromKieModuleFromDrl(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 OOPathCepTest method populateAndVerifyLengthWindowCase.
private void populateAndVerifyLengthWindowCase(final KieBase kieBase) {
this.initKieSession(kieBase);
final MessageEvent pingEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Ping"));
this.kieSession.insert(pingEvent);
final MessageEvent ping2Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping2Event);
final MessageEvent ping3Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping3Event);
this.kieSession.fireAllRules();
Assertions.assertThat(this.events).as("The rule should have fired for 2 events").contains(ping2Event, ping3Event);
this.events.clear();
final MessageEvent pongEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Pong"));
this.kieSession.insert(pongEvent);
final MessageEvent ping4Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
this.kieSession.insert(ping4Event);
this.kieSession.fireAllRules();
Assertions.assertThat(this.events).as("The rule should have fired for ping event only").contains(ping4Event);
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorOverlapsWithOOPath.
@Test
public void testTemporalOperatorOverlapsWithOOPath() {
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 overlaps[ 1s ] ev1 )\n" + "then\n" + " messages.add( $message );\n" + "end\n";
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl(MODULE_GROUP_ID, kieBaseTestConfiguration, drl);
final SessionPseudoClock clock = this.initKieSessionWithPseudoClock(kieBase);
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), 1), clock, 2);
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), 1), 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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS), clock, 1);
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), DEFAULT_DURATION_IN_SECS));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
Aggregations