Search in sources :

Example 6 with Message

use of org.drools.testcoverage.common.model.Message 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);
}
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 7 with Message

use of org.drools.testcoverage.common.model.Message 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);
}
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 8 with Message

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

the class OOPathCepTest method insertEventAndAdvanceClock.

private Message insertEventAndAdvanceClock(final MessageEvent messageEvent, final SessionPseudoClock clock, final long timeInSeconds) {
    final Message result = this.insertEvent(messageEvent);
    clock.advanceTime(timeInSeconds, TimeUnit.SECONDS);
    return result;
}
Also used : Message(org.drools.testcoverage.common.model.Message)

Example 9 with Message

use of org.drools.testcoverage.common.model.Message 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);
}
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 10 with Message

use of org.drools.testcoverage.common.model.Message 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);
}
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)22 MessageEvent (org.drools.testcoverage.common.model.MessageEvent)18 Test (org.junit.Test)18 KieBase (org.kie.api.KieBase)17 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)14 KieSession (org.kie.api.runtime.KieSession)4 Resource (org.kie.api.io.Resource)2 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 KieSessionTest (org.drools.testcoverage.common.KieSessionTest)1 TrackingAgendaEventListener (org.drools.testcoverage.common.listener.TrackingAgendaEventListener)1 Cheese (org.drools.testcoverage.common.model.Cheese)1 Customer (org.drools.testcoverage.common.model.Customer)1 KieResources (org.kie.api.io.KieResources)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1