use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.
the class ActivityTest method testMultipleBusinessRuleTaskWithDataInputsWithPersistence.
@Test
public void testMultipleBusinessRuleTaskWithDataInputsWithPersistence() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultipleRuleTasksWithDataInput.bpmn2", "BPMN2-MultipleRuleTasks.drl");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new TriggerRulesEventListener(ksession));
List<String> listPerson = new ArrayList<String>();
List<String> listAddress = new ArrayList<String>();
ksession.setGlobal("listPerson", listPerson);
ksession.setGlobal("listAddress", listAddress);
Person person = new Person();
person.setName("john");
Address address = new Address();
address.setStreet("5th avenue");
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", person);
params.put("address", address);
ProcessInstance processInstance = ksession.startProcess("multiple-rule-tasks", params);
assertEquals(1, listPerson.size());
assertEquals(1, listAddress.size());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromClassPath.
@Test(timeout = 20000)
public void testStartTimerCycleFromClassPath() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
KieBase kbase = createKnowledgeBase("BPMN2-StartTimerCycle.bpmn2");
try {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
logger.info("dispose");
ksession.dispose();
countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<Long> list2 = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list2.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
ksession.dispose();
assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
} finally {
ksession = createKnowledgeSession(kbase);
abortProcessInstances(ksession);
ksession.dispose();
}
}
use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener 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);
}
use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDisc.
@Test(timeout = 20000)
public void testStartTimerCycleFromDisc() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
KieBase kbase = createKnowledgeBaseFromDisc("BPMN2-StartTimerCycle.bpmn2");
try {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
logger.info("dispose");
ksession.dispose();
countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<Long> list2 = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list2.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
abortProcessInstances(ksession);
ksession.dispose();
} finally {
ksession = createKnowledgeSession(kbase);
abortProcessInstances(ksession);
ksession.dispose();
}
}
use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDiscDRL.
@Test
@Ignore("beta4 phreak")
public void testStartTimerCycleFromDiscDRL() throws Exception {
KieBase kbase = createKnowledgeBaseFromDisc("rules-timer.drl");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
ksession.fireAllRules();
Thread.sleep(5000);
assertEquals(2, list.size());
logger.info("dispose");
ksession.dispose();
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<String> list2 = new ArrayList<String>();
ksession.setGlobal("list", list2);
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
ksession.fireAllRules();
Thread.sleep(6000);
assertEquals(3, list2.size());
}
Aggregations