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);
}
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);
}
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);
}
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();
}
}
Aggregations