use of org.kie.api.event.rule.DebugAgendaEventListener in project drools by kiegroup.
the class Misc2Test method testLockOnActiveWithModifyNoEager.
@Test
public void testLockOnActiveWithModifyNoEager() {
// DROOLS-280
String drl = "" + "package org.drools.test; \n" + "import org.drools.compiler.Person; \n" + "" + "rule \"Rule1\" \n" + "salience 1 \n" + "lock-on-active true\n" + "when\n" + " $p: Person()\n" + "then\n" + " System.out.println( \"Rule1\" ); \n" + " modify( $p ) { setAge( 44 ); }\n" + "end;\n" + "\n" + "rule \"Rule2\"\n" + "lock-on-active true\n" + "when\n" + " $p: Person() \n" + " String() from $p.getName() \n" + "then\n" + " System.out.println( \"Rule2\" + $p ); " + " modify ( $p ) { setName( \"john\" ); } \n" + "end";
KieBase kb = loadKnowledgeBaseFromString(drl);
KieSession ks = kb.newKieSession();
ks.addEventListener(new DebugAgendaEventListener());
ks.fireAllRules();
Person p = new Person("mark", 76);
ks.insert(p);
ks.fireAllRules();
assertEquals(44, p.getAge());
assertEquals("john", p.getName());
}
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