Search in sources :

Example 1 with StockTickEvent

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();
    }
}
Also used : StockTickEvent(org.drools.testcoverage.common.model.StockTickEvent) StockTick(org.drools.testcoverage.common.model.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) InternalFactHandle(org.drools.core.common.InternalFactHandle) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 StockTick (org.drools.testcoverage.common.model.StockTick)1 StockTickEvent (org.drools.testcoverage.common.model.StockTickEvent)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)1