Search in sources :

Example 1 with StockTickEx

use of org.drools.modelcompiler.domain.StockTickEx in project drools by kiegroup.

the class CepTest method testBeforeOnLongFieldsWithDifferentMethod.

@Test
public void testBeforeOnLongFieldsWithDifferentMethod() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "import " + StockTickEx.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + "declare StockTickEx @timestamp(timeFieldExAsLong) end\n" + "rule R when\n" + "    $a : StockTickEx( company == \"DROO\" )\n" + "    StockTick( company == \"ACME\", timeFieldAsLong before[5,8] $a.timeFieldExAsLong )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("ACME").setTimeField(0));
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTickEx(org.drools.modelcompiler.domain.StockTickEx) StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 2 with StockTickEx

use of org.drools.modelcompiler.domain.StockTickEx in project drools by kiegroup.

the class CepTest method testAfterOnLongFieldsBindingFirstWithDifferentMethod.

@Test
public void testAfterOnLongFieldsBindingFirstWithDifferentMethod() throws Exception {
    String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "import " + StockTickEx.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + "declare StockTickEx @timestamp(timeFieldExAsLong) end\n" + "rule R when\n" + "    $a : StockTickEx( company == \"DROO\" )\n" + "    StockTick( company == \"ACME\", $a.timeFieldExAsLong after[5,8] timeFieldAsLong )\n" + "then\n" + "  System.out.println(\"fired\");\n" + "end\n";
    KieSession ksession = getKieSession(getCepKieModuleModel(), str);
    SessionPseudoClock clock = ksession.getSessionClock();
    ksession.insert(new StockTick("ACME").setTimeField(0));
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(6));
    assertEquals(1, ksession.fireAllRules());
    ksession.insert(new StockTickEx("DROO").setTimeFieldEx(10));
    assertEquals(0, ksession.fireAllRules());
}
Also used : StockTickEx(org.drools.modelcompiler.domain.StockTickEx) StockTick(org.drools.modelcompiler.domain.StockTick) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

StockTick (org.drools.modelcompiler.domain.StockTick)2 StockTickEx (org.drools.modelcompiler.domain.StockTickEx)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)2