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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations