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.compiler;\n" + "\n" + "import org.drools.compiler.compiler.TypeDeclarationTest.EventBar.*;\n" + "" + "declare Foo\n" + " @role( event )\n" + "end\n" + "" + "rule R when Foo() then end";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
System.err.println(kbuilder.getErrors());
assertFalse(kbuilder.hasErrors());
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addPackages(kbuilder.getKnowledgePackages());
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 testMultipleAnnotationDeclarations.
@Test
public void testMultipleAnnotationDeclarations() {
String str1 = "";
str1 += "package org.kie1 " + "" + "declare Foo \n" + " name : String " + " age : int " + "end ";
String str2 = "";
str2 += "package org.kie2 " + "" + "declare org.kie1.Foo " + " @role(event) " + "end ";
String str3 = "";
str3 += "package org.kie3 " + "" + "declare org.kie1.Foo " + " @propertyReactive " + "end ";
String str4 = "" + "package org.kie4; " + "import org.kie1.Foo; " + "" + "rule Check " + "when " + " $f : Foo( name == 'bar' ) " + "then " + " modify( $f ) { setAge( 99 ); } " + "end ";
KieHelper helper = new KieHelper();
helper.addContent(str1, ResourceType.DRL);
helper.addContent(str2, ResourceType.DRL);
helper.addContent(str3, ResourceType.DRL);
helper.addContent(str4, ResourceType.DRL);
List<Message> msg = helper.verify().getMessages(Message.Level.ERROR);
System.out.println(msg);
assertEquals(0, msg.size());
KieBase kieBase = helper.build();
FactType type = kieBase.getFactType("org.kie1", "Foo");
assertEquals(2, type.getFields().size());
Object foo = null;
try {
foo = type.newInstance();
type.set(foo, "name", "bar");
assertEquals("bar", type.get(foo, "name"));
} catch (InstantiationException e) {
fail(e.getMessage());
} catch (IllegalAccessException e) {
fail(e.getMessage());
}
KieSession session = kieBase.newKieSession();
FactHandle handle = session.insert(foo);
int n = session.fireAllRules(5);
assertTrue(handle instanceof EventFactHandle);
assertEquals(1, n);
assertEquals(99, type.get(foo, "age"));
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class DroolsAbstractPMMLTest method reportWMObjects.
public String reportWMObjects(KieSession session) {
PriorityQueue<String> queue = new PriorityQueue<String>();
for (FactHandle fh : session.getFactHandles()) {
Object o;
if (fh instanceof EventFactHandle) {
EventFactHandle efh = (EventFactHandle) fh;
queue.add("\t " + efh.getStartTimestamp() + "\t" + efh.getObject().toString() + "\n");
} else {
o = ((DefaultFactHandle) fh).getObject();
queue.add("\t " + o.toString() + " >> " + System.identityHashCode(o.getClass()) + "\n");
}
}
String ans = " ---------------- WM " + session.getObjects().size() + " --------------\n";
while (!queue.isEmpty()) ans += queue.poll();
ans += " ---------------- END WM -----------\n";
return ans;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class ConstrainedDataDictionaryTest method testProperties.
@Test
public void testProperties() throws Exception {
getKSession().getEntryPoint("in_Vallued").insert(1);
getKSession().getEntryPoint("in_Intervalled").insert(8.3);
getKSession().getEntryPoint("in_Cat").insert("aa");
getKSession().getEntryPoint("in_Sort").insert(1);
getKSession().fireAllRules();
Collection<EventFactHandle> fact1 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Vallued").getFactClass()));
assertEquals(1, fact1.size());
// assertEquals(true, getKbase().getFactType(packageName, "Vallued").get(fact1.iterator().next().getObject(), "continuous"));
Collection<EventFactHandle> fact2 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Intervalled").getFactClass()));
assertEquals(1, fact2.size());
// assertEquals(true, getKbase().getFactType(packageName,"Intervalled").get(fact2.iterator().next().getObject(),"continuous"));
Collection<EventFactHandle> fact3 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Cat").getFactClass()));
assertEquals(1, fact3.size());
// assertEquals(true, getKbase().getFactType(packageName,"Cat").get(fact3.iterator().next().getObject(),"categorical"));
Collection<EventFactHandle> fact4 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Sort").getFactClass()));
assertEquals(1, fact4.size());
// assertEquals(true, getKbase().getFactType(packageName,"Sort").get(fact4.iterator().next().getObject(),"ordinal"));
checkGeneratedRules();
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class TemporalEvaluatorFactoryTest method testStartedBy.
@Test
public void testStartedBy() {
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, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
final Object[][] data = { { foo, "startedby", bar, Boolean.TRUE }, { foo, "startedby", drool, Boolean.FALSE }, { foo, "startedby", mole, Boolean.FALSE }, { bar, "startedby", foo, Boolean.FALSE }, { foo, "not startedby", bar, Boolean.FALSE }, { foo, "not startedby", drool, Boolean.TRUE }, { foo, "not startedby", mole, Boolean.TRUE }, { bar, "not startedby", foo, Boolean.TRUE }, { foo, "startedby[1]", bar, Boolean.TRUE }, { foo, "startedby[1]", drool, Boolean.FALSE }, { foo, "startedby[1]", mole, Boolean.TRUE }, { bar, "startedby[1]", foo, Boolean.FALSE }, { foo, "not startedby[1]", bar, Boolean.FALSE }, { foo, "not startedby[1]", drool, Boolean.TRUE }, { foo, "not startedby[1]", mole, Boolean.FALSE }, { bar, "not startedby[1]", foo, Boolean.TRUE }, { foo, "startedby[3]", mole, Boolean.TRUE } };
runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Aggregations