Search in sources :

Example 36 with Message

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.getKieBaseFromKieModuleFromDrl(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);
}
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 37 with Message

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.getKieBaseFromKieModuleFromDrl(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 38 with Message

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.getKieBaseFromKieModuleFromDrl(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);
}
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 39 with Message

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

the class ConstraintsTest method testExpressionConstraints.

private void testExpressionConstraints(final String drl) {
    final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("constraints-test", kieBaseTestConfiguration, drl);
    final KieSession ksession = kbase.newKieSession();
    try {
        final Mailbox mbox = new Mailbox(Mailbox.TEST_EMAIL);
        final Message message = new Message();
        message.setMessage("Welcome");
        message.setStatus(Message.HELLO);
        mbox.getFolder(Mailbox.FolderType.INBOX).add(message);
        ksession.insert(mbox);
        ksession.insert(message);
        assertEquals(1, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
}
Also used : Message(org.drools.testcoverage.common.model.Message) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession)

Aggregations

Message (org.drools.testcoverage.common.model.Message)39 Test (org.junit.Test)32 KieBase (org.kie.api.KieBase)21 KieSession (org.kie.api.runtime.KieSession)20 MessageEvent (org.drools.testcoverage.common.model.MessageEvent)18 KieServices (org.kie.api.KieServices)14 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)14 KieContainer (org.kie.api.runtime.KieContainer)13 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)13 ReleaseId (org.kie.api.builder.ReleaseId)11 ArrayList (java.util.ArrayList)4 KieFileSystem (org.kie.api.builder.KieFileSystem)4 KieBuilder (org.kie.api.builder.KieBuilder)3 Resource (org.kie.api.io.Resource)3 IncrementalResults (org.kie.internal.builder.IncrementalResults)3 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)3 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Cheese (org.drools.testcoverage.common.model.Cheese)2 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)2