use of org.drools.testcoverage.common.model.StockTickEvent in project drools by kiegroup.
the class CepEspTest method testAnnotatedEventAssertion.
@Test(timeout = 10000)
public void testAnnotatedEventAssertion() {
final String drl = "package org.drools.compiler.test;\n" + "\n" + "import " + StockTickEvent.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List results;\n" + "\n" + "rule \"Check event\"\n" + "when\n" + " $st : StockTickEvent( company == \"ACME\" )\n" + "then\n" + " results.add( $st );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
final KieSession session = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration(), null);
try {
final SessionPseudoClock clock = session.getSessionClock();
final List results = new ArrayList();
session.setGlobal("results", results);
final StockTick tick1 = new StockTickEvent(1, "DROO", 50, 10000);
final StockTick tick2 = new StockTickEvent(2, "ACME", 10, 10010);
final StockTick tick3 = new StockTickEvent(3, "ACME", 10, 10100);
final StockTick tick4 = new StockTickEvent(4, "DROO", 50, 11000);
final InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
clock.advanceTime(10, TimeUnit.SECONDS);
final InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
clock.advanceTime(30, TimeUnit.SECONDS);
final InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
clock.advanceTime(20, TimeUnit.SECONDS);
final InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
clock.advanceTime(10, TimeUnit.SECONDS);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("results")).size());
} finally {
session.dispose();
}
}
Aggregations