Search in sources :

Example 1 with MessageEvent

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

the class OOPathCepTest method testTemporalOperatorFinishedByWithOOPath.

@Test
public void testTemporalOperatorFinishedByWithOOPath() {
    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 finishedby 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("Ping"), DEFAULT_DURATION_IN_SECS), clock, 1);
    final Message pongMessage = 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();
    this.insertEvent(new MessageEvent(MessageEvent.Type.sent, new Message("Ping"), DEFAULT_DURATION_IN_SECS - 1000));
    this.kieSession.fireAllRules();
    Assertions.assertThat(this.messages).as("The last event should make the rule fire").containsExactlyInAnyOrder(pongMessage);
}
Also used : Message(org.drools.testcoverage.common.model.Message) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieBase(org.kie.api.KieBase) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) Test(org.junit.Test)

Example 2 with MessageEvent

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

the class OOPathCepTest method testTemporalOperatorStartedByWithOOPath.

@Test
public void testTemporalOperatorStartedByWithOOPath() {
    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 startedby[ 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);
}
Also used : Message(org.drools.testcoverage.common.model.Message) KieBase(org.kie.api.KieBase) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) Test(org.junit.Test)

Example 3 with MessageEvent

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

the class OOPathCepTest method populateAndVerifyTimeWindowCase.

private void populateAndVerifyTimeWindowCase(final KieBase kieBase) {
    final KieSessionConfiguration sessionConfiguration = KieSessionUtil.getKieSessionConfigurationWithClock(ClockTypeOption.get("pseudo"), null);
    this.initKieSession(kieBase, sessionConfiguration);
    final SessionPseudoClock clock = this.kieSession.getSessionClock();
    final MessageEvent pingEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Ping"));
    this.kieSession.insert(pingEvent);
    clock.advanceTime(1, TimeUnit.SECONDS);
    final MessageEvent ping2Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
    this.kieSession.insert(ping2Event);
    clock.advanceTime(1, TimeUnit.SECONDS);
    final MessageEvent ping3Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
    this.kieSession.insert(ping3Event);
    clock.advanceTime(1, TimeUnit.SECONDS);
    this.kieSession.fireAllRules();
    Assertions.assertThat(this.events).as("The rule should have fired for 2 events").containsExactlyInAnyOrder(ping2Event, ping3Event);
    this.events.clear();
    final MessageEvent pongEvent = new MessageEvent(MessageEvent.Type.sent, new Message("Pong"));
    this.kieSession.insert(pongEvent);
    clock.advanceTime(1, TimeUnit.SECONDS);
    final MessageEvent ping4Event = new MessageEvent(MessageEvent.Type.received, new Message("Ping"));
    this.kieSession.insert(ping4Event);
    clock.advanceTime(1, TimeUnit.SECONDS);
    this.kieSession.fireAllRules();
    Assertions.assertThat(this.events).as("The rule should have fired for ping event only").contains(ping4Event);
}
Also used : Message(org.drools.testcoverage.common.model.Message) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration)

Example 4 with MessageEvent

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

the class OOPathCepTest method testTemporalOperatorMeetsWithOOPath.

@Test
public void testTemporalOperatorMeetsWithOOPath() {
    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 meets[ 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);
}
Also used : Message(org.drools.testcoverage.common.model.Message) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieBase(org.kie.api.KieBase) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) Test(org.junit.Test)

Example 5 with MessageEvent

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

the class OOPathCepTest method testTemporalOperatorBeforeWithOOPath.

@Test
public void testTemporalOperatorBeforeWithOOPath() {
    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 before 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("Ping")), clock, 1);
    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);
}
Also used : Message(org.drools.testcoverage.common.model.Message) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieBase(org.kie.api.KieBase) MessageEvent(org.drools.testcoverage.common.model.MessageEvent) Test(org.junit.Test)

Aggregations

Message (org.drools.testcoverage.common.model.Message)18 MessageEvent (org.drools.testcoverage.common.model.MessageEvent)18 Test (org.junit.Test)15 KieBase (org.kie.api.KieBase)15 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)14 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)2 TrackingAgendaEventListener (org.drools.testcoverage.common.listener.TrackingAgendaEventListener)1 Resource (org.kie.api.io.Resource)1 KieSession (org.kie.api.runtime.KieSession)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1