use of org.drools.testcoverage.common.model.MessageEvent in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorAfterWithOOPath.
@Test
public void testTemporalOperatorAfterWithOOPath() {
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" + "end\n" + "rule R when\n" + " ev1: MessageEvent( /msg[ message == 'Ping' ] )\n" + " ev2: MessageEvent( $message: /msg[ message == 'Pong' ], this after 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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong")), clock, 1);
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Ping")), 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")));
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.MessageEvent in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorFinishesWithOOPath.
@Test
public void testTemporalOperatorFinishesWithOOPath() {
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 finishes 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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS), clock, 1);
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), 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 - 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.MessageEvent in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorMetByWithOOPath.
@Test
public void testTemporalOperatorMetByWithOOPath() {
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" + "end\n" + "rule R when\n" + " ev1: MessageEvent( /msg[ message == 'Ping' ] )\n" + " ev2: MessageEvent( $message: /msg[ message == 'Pong' ], this metby[ 1s ] 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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong")), clock, 2);
this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping")));
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")));
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.MessageEvent in project drools by kiegroup.
the class OOPathCepTest method testTemporalOperatorOverlappedByWithOOPath.
@Test
public void testTemporalOperatorOverlappedByWithOOPath() {
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 overlappedby[ 1s ] 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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong"), DEFAULT_DURATION_IN_SECS), clock, 1);
this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), 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));
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.MessageEvent in project drools by kiegroup.
the class OOPathCepTest method testEventExplicitExpirationWithOOPath.
@Test
public void testEventExplicitExpirationWithOOPath() {
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" + " @expires( 2s )\n" + "end\n" + "rule R when\n" + " MessageEvent( /msg[ message == 'Ping' ] )\n" + " MessageEvent( $message: /msg[ message == 'Pong' ] )\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.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Ping")), clock, 3);
final Message pongMessage = this.insertEventAndAdvanceClock(new MessageEvent(MessageEvent.Type.sent, new Message("Pong")), clock, 1);
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")));
this.kieSession.fireAllRules();
Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
Aggregations