Search in sources :

Example 46 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testStarts.

@Test
public void testStarts() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 2, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 1, 4, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { bar, "starts", foo, Boolean.TRUE }, { drool, "starts", foo, Boolean.FALSE }, { mole, "starts", foo, Boolean.FALSE }, { foo, "starts", bar, Boolean.FALSE }, { bar, "not starts", foo, Boolean.FALSE }, { drool, "not starts", foo, Boolean.TRUE }, { mole, "not starts", foo, Boolean.TRUE }, { foo, "not starts", bar, Boolean.TRUE }, { bar, "starts[1]", foo, Boolean.TRUE }, { drool, "starts[1]", foo, Boolean.FALSE }, { mole, "starts[1]", foo, Boolean.TRUE }, { foo, "starts[1]", bar, Boolean.FALSE }, { bar, "not starts[1]", foo, Boolean.FALSE }, { drool, "not starts[1]", foo, Boolean.TRUE }, { mole, "not starts[1]", foo, Boolean.FALSE }, { foo, "not starts[1]", bar, Boolean.TRUE }, { mole, "starts[3]", foo, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 47 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testOverlaps.

@Test
public void testOverlaps() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 8, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 7, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 11, 5, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 5, 5, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { foo, "overlaps", bar, Boolean.TRUE }, { foo, "overlaps", drool, Boolean.FALSE }, { foo, "overlaps", mole, Boolean.FALSE }, { foo, "not overlaps", bar, Boolean.FALSE }, { foo, "not overlaps", drool, Boolean.TRUE }, { foo, "not overlaps", mole, Boolean.TRUE }, { foo, "overlaps[3]", bar, Boolean.TRUE }, { foo, "overlaps[3]", drool, Boolean.FALSE }, { foo, "overlaps[3]", mole, Boolean.FALSE }, { foo, "overlaps[2]", bar, Boolean.FALSE }, { foo, "overlaps[6]", mole, Boolean.FALSE }, { foo, "not overlaps[3]", bar, Boolean.FALSE }, { foo, "not overlaps[3]", drool, Boolean.TRUE }, { foo, "not overlaps[3]", mole, Boolean.TRUE }, { foo, "not overlaps[2]", bar, Boolean.TRUE }, { foo, "not overlaps[6]", mole, Boolean.TRUE }, { foo, "overlaps[1,3]", bar, Boolean.TRUE }, { foo, "overlaps[1,3]", drool, Boolean.FALSE }, { foo, "overlaps[1,3]", mole, Boolean.FALSE }, { foo, "overlaps[4,6]", bar, Boolean.FALSE }, { foo, "overlaps[1,8]", mole, Boolean.FALSE }, { foo, "not overlaps[1,3]", bar, Boolean.FALSE }, { foo, "not overlaps[1,3]", drool, Boolean.TRUE }, { foo, "not overlaps[1,3]", mole, Boolean.TRUE }, { foo, "not overlaps[4,6]", bar, Boolean.TRUE }, { foo, "not overlaps[1,8]", mole, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 48 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TypeDeclarationTest method testTypeDeclarationWithInnerClasses.

@Test
public void testTypeDeclarationWithInnerClasses() {
    // DROOLS-150
    String str = "";
    str += "package org.drools.mvel.compiler;\n" + "\n" + "import org.drools.mvel.compiler.compiler.TypeDeclarationTest.EventBar.*;\n" + "" + "declare Foo\n" + " @role( event )\n" + "end\n" + "" + "rule R when Foo() then end";
    KieBase kBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession knowledgeSession = kBase.newKieSession();
    FactHandle handle = knowledgeSession.insert(new EventBar.Foo());
    assertTrue(handle instanceof EventFactHandle);
}
Also used : EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 49 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TypeDeclarationTest method testTypeDeclarationWithInnerClassesImport.

@Test
public void testTypeDeclarationWithInnerClassesImport() {
    // DROOLS-150
    String str = "";
    str += "package org.drools.mvel.compiler;\n" + "\n" + "import org.drools.mvel.compiler.compiler.TypeDeclarationTest.EventBar.Foo;\n" + "" + "declare Foo\n" + " @role( event )\n" + "end\n" + "" + "rule R when Foo() then end";
    KieBase kBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession knowledgeSession = kBase.newKieSession();
    FactHandle handle = knowledgeSession.insert(new EventBar.Foo());
    assertTrue(handle instanceof EventFactHandle);
}
Also used : EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 50 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class ExtendsTest method testInheritAnnotationsInOtherPackage.

@Test
public void testInheritAnnotationsInOtherPackage() throws Exception {
    String s1 = "package org.drools.mvel.compiler.test.pack1;\n" + "global java.util.List list;" + "\n" + "declare Event\n" + "@role(event)" + "  id    : int\n" + "end\n" + "\n" + "rule \"X\"\n" + "when\n" + "  $s1 : Event()\n" + "then\n" + "  System.out.println( $s1 );\n" + "  list.add( $s1.getId() );\n " + "end";
    String s2 = "package org.drools.mvel.compiler.test.pack2;\n" + "\n" + "import org.drools.mvel.compiler.test.pack1.Event;\n" + "global java.util.List list;" + "\n" + "declare Event end\n" + "\n" + "declare SubEvent extends Event\n" + "end\n" + "\n" + "rule \"Init\"\n" + "when\n" + "then\n" + "  list.add( 0 );\n" + "  insert( new SubEvent( 1 ) );\n" + "  insert( new SubEvent( 2 ) );\n" + "end\n" + "\n" + "rule \"Seq\"\n" + "when\n" + "  $s1 : SubEvent( id == 1 )\n" + "  $s2 : SubEvent( id == 2, this after[0,10s] $s1 )\n" + "then\n" + "  list.add( 3 );\n" + "  System.out.println( $s1 + \" after \" + $s1 );\n" + "end \n" + "\n" + "rule \"Seq 2 \"\n" + "when\n" + "  $s1 : Event( id == 1 )\n" + "  $s2 : Event( id == 2, this after[0,10s] $s1 )\n" + "then\n" + "  list.add( 4 );\n" + "  System.out.println( $s1 + \" after II \" + $s1 );\n" + "end";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, s1, s2);
    KieSession kSession = kbase.newKieSession();
    List list = new ArrayList();
    kSession.setGlobal("list", list);
    kSession.fireAllRules();
    for (Object o : kSession.getObjects()) {
        FactHandle h = kSession.getFactHandle(o);
        assertTrue(h instanceof EventFactHandle);
    }
    System.out.println(list);
    assertEquals(5, list.size());
    assertTrue(list.contains(0));
    assertTrue(list.contains(1));
    assertTrue(list.contains(2));
    assertTrue(list.contains(3));
    assertTrue(list.contains(4));
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Aggregations

EventFactHandle (org.drools.core.common.EventFactHandle)86 Test (org.junit.Test)51 KieSession (org.kie.api.runtime.KieSession)23 KieBase (org.kie.api.KieBase)18 InternalFactHandle (org.drools.core.common.InternalFactHandle)16 DisconnectedWorkingMemoryEntryPoint (org.drools.core.common.DisconnectedWorkingMemoryEntryPoint)13 DisconnectedWorkingMemoryEntryPoint (org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint)13 FactHandle (org.kie.api.runtime.rule.FactHandle)11 DuringEvaluatorDefinition (org.drools.core.base.evaluators.DuringEvaluatorDefinition)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)10 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)6 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)5 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)5 PropagationContext (org.drools.core.spi.PropagationContext)5 StockTick (org.drools.testcoverage.common.model.StockTick)5 EntryPointId (org.drools.core.rule.EntryPointId)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4