use of org.drools.testcoverage.common.model.StockTick in project drools by kiegroup.
the class CepEspTest method testEventAssertionWithDuration.
@Test(timeout = 10000)
public void testEventAssertionWithDuration() {
final String drl = "package org.drools.compiler\n" + "\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List results;\n" + "\n" + "declare StockTick \n" + " @role( event )\n" + " @duration( duration )\n" + " @timestamp( time )\n" + "end\n" + "\n" + "rule \"Check event\"\n" + "when\n" + " $st : StockTick( 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 List results = new ArrayList();
session.setGlobal("results", results);
final StockTick tick1 = new StockTick(1, "DROO", 50, 10000, 5);
final StockTick tick2 = new StockTick(2, "ACME", 10, 11000, 10);
final StockTick tick3 = new StockTick(3, "ACME", 10, 12000, 8);
final StockTick tick4 = new StockTick(4, "DROO", 50, 13000, 7);
final InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
final InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
final InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
final InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
final EventFactHandle eh1 = (EventFactHandle) handle1;
final EventFactHandle eh2 = (EventFactHandle) handle2;
final EventFactHandle eh3 = (EventFactHandle) handle3;
final EventFactHandle eh4 = (EventFactHandle) handle4;
assertEquals(tick1.getTime(), eh1.getStartTimestamp());
assertEquals(tick2.getTime(), eh2.getStartTimestamp());
assertEquals(tick3.getTime(), eh3.getStartTimestamp());
assertEquals(tick4.getTime(), eh4.getStartTimestamp());
assertEquals(tick1.getDuration(), eh1.getDuration());
assertEquals(tick2.getDuration(), eh2.getDuration());
assertEquals(tick3.getDuration(), eh3.getDuration());
assertEquals(tick4.getDuration(), eh4.getDuration());
session.fireAllRules();
assertEquals(2, results.size());
} finally {
session.dispose();
}
}
use of org.drools.testcoverage.common.model.StockTick in project drools by kiegroup.
the class CepEspTest method testArbitraryDates.
private void testArbitraryDates(final String drlClasspathResource, final long tick1Time, final long tick2Time) {
final KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources("cep-esp-test", kieBaseTestConfiguration, drlClasspathResource);
final KieSession wm = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration(), null);
try {
final List<?> results = new ArrayList<>();
wm.setGlobal("results", results);
final StockTick tick1 = new StockTick(1, "DROO", 50, tick1Time, 3);
final StockTick tick2 = new StockTick(2, "ACME", 10, tick2Time, 3);
final InternalFactHandle handle2 = (InternalFactHandle) wm.insert(tick2);
final InternalFactHandle handle1 = (InternalFactHandle) wm.insert(tick1);
assertNotNull(handle1);
assertNotNull(handle2);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
wm.fireAllRules();
assertEquals(4, results.size());
assertEquals(tick1, results.get(0));
assertEquals(tick2, results.get(1));
assertEquals(tick1, results.get(2));
assertEquals(tick2, results.get(3));
} finally {
wm.dispose();
}
}
use of org.drools.testcoverage.common.model.StockTick in project drools by kiegroup.
the class CepEspTest method testEventDeclarationForInterfaces.
@Test(timeout = 10000)
public void testEventDeclarationForInterfaces() {
final String drl = "package org.drools.compiler\n" + "import " + StockTick.class.getCanonicalName() + "\n" + "declare StockTick \n" + " @role( event )\n" + " @timestamp( dateTimestamp )\n" + "end\n" + "\n" + "rule \"Check event\"\n" + "when\n" + " $st : StockTick( company == \"ACME\" )\n" + "then\n" + " // no-op\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
final KieSession session = kbase.newKieSession();
try {
final StockTick tick1 = new StockTick(1, "DROO", 50, 10000);
final StockTick tick2 = new StockTick(2, "ACME", 10, 10010);
final StockTick tick3 = new StockTick(3, "ACME", 10, 10100);
final StockTick tick4 = new StockTick(4, "DROO", 50, 11000);
final InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
final InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
final InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
final InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
} finally {
session.dispose();
}
}
Aggregations