use of org.kie.api.event.rule.DebugAgendaEventListener in project drools by kiegroup.
the class RuleTest method testCheck.
@Test
public void testCheck() {
String drl = "package i.p;\n" + "import " + LongHolder.class.getCanonicalName() + "\n" + "import " + WeirdObject.class.getCanonicalName() + "\n" + "import " + TestObjectEnum.class.getCanonicalName() + "\n" + "rule fileArule1 when\n" + " $t : LongHolder()\n" + " WeirdObject(added == $t.value, status == TestObjectEnum.ONE.getValue() )\n" + "then\n" + "end\n" + "rule fileArule2 when\n" + " $t : LongHolder()\n" + " WeirdObject(nested.id == $t.value, status == 0 )\n" + "then\n" + "end\n";
String drl2 = "package c.t.p;\n" + "import " + WeirdObject.class.getCanonicalName() + "\n" + "import " + TestObjectEnum.class.getCanonicalName() + "\n" + "rule fileBrule1 when\n" + " WeirdObject(status == 1)\n" + "then\n" + "end\n";
KieSession kieSession = new KieHelper().addContent(drl2, ResourceType.DRL).addContent(drl, ResourceType.DRL).build().newKieSession();
ReteDiagram.newInstance().diagramRete(kieSession);
kieSession.addEventListener(new DebugAgendaEventListener());
kieSession.insert(new LongHolder(12345L));
kieSession.insert(new WeirdObject(1, new WeirdNested(12345L)));
kieSession.fireAllRules();
}
use of org.kie.api.event.rule.DebugAgendaEventListener in project drools by kiegroup.
the class TraitTest method testTraitDonLegacyClassWithoutEmptyConstructor.
@Test
public void testTraitDonLegacyClassWithoutEmptyConstructor() {
String drl = "package org.drools.compiler.trait.test;\n" + "\n" + "import " + TraitableFoo.class.getCanonicalName() + ";" + "import org.drools.core.factmodel.traits.Traitable;\n" + "\n" + "" + "declare trait Bar\n" + "end\n" + "\n" + "rule \"Don\"\n" + "no-loop \n" + "when\n" + " $f : TraitableFoo( )\n" + "then\n" + " Bar b = don( $f, Bar.class );\n" + "end";
KieSession ksession = getSessionFromString(drl);
TraitFactoryImpl.setMode(mode, ksession.getKieBase());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.insert(new TraitableFoo("xx", 0, null));
ksession.fireAllRules();
for (Object o : ksession.getObjects()) {
System.out.println(o);
}
assertEquals(2, ksession.getObjects().size());
}
use of org.kie.api.event.rule.DebugAgendaEventListener in project jbpm by kiegroup.
the class ActivityTest method testRuleTaskWithFactsWithPersistence.
@Test
@RequirePersistence
public void testRuleTaskWithFactsWithPersistence() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
ksession = createKnowledgeSession(kbase);
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
ksession.addEventListener(new DebugAgendaEventListener());
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "SomeString");
ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
assertProcessInstanceFinished(processInstance, ksession);
params = new HashMap<String, Object>();
try {
processInstance = ksession.startProcess("RuleTask", params);
fail("Should fail");
} catch (Exception e) {
e.printStackTrace();
}
params = new HashMap<String, Object>();
params.put("x", "SomeString");
processInstance = ksession.startProcess("RuleTask", params);
assertProcessInstanceFinished(processInstance, ksession);
}
Aggregations