use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testMultipleInOutgoingSequenceFlows.
@Test
public void testMultipleInOutgoingSequenceFlows() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
System.setProperty("jbpm.enable.multi.con", "true");
KieBase kbase = createKnowledgeBase("BPMN2-MultipleInOutgoingSequenceFlows.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertEquals(0, list.size());
countDownListener.waitTillCompleted();
assertEquals(1, list.size());
System.clearProperty("jbpm.enable.multi.con");
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveParallelExclusiveSplitLoop.
@Test
public void testInclusiveParallelExclusiveSplitLoop() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveNestedInParallelNestedInExclusive.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("testWI", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", new SystemOutWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Integer x = (Integer) workItem.getParameter("input1");
x++;
Map<String, Object> results = new HashMap<String, Object>();
results.put("output1", x);
manager.completeWorkItem(workItem.getId(), results);
}
});
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", -1);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(12, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XORGateway-converging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ANDGateway-diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ORGateway-diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("testWI3"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("testWI2"));
assertEquals(4, (int) nodeInstanceExecutionCounter.get("ORGateway-converging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XORGateway-diverging"));
assertEquals(4, (int) nodeInstanceExecutionCounter.get("ANDGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI6"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveJoinWithLoopAndHumanTasks.
@Test
public void testInclusiveJoinWithLoopAndHumanTasks() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithHumanTasksProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("firstXor", true);
params.put("secondXor", true);
params.put("thirdXor", true);
ProcessInstance processInstance = ksession.startProcess("InclusiveWithAdvancedLoop", params);
// simulate completion of first task
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
WorkItem remainingWork = null;
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
// complete second task that will trigger converging OR gateway
if (wi.getParameter("NodeName").equals("HT Form2")) {
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
} else {
remainingWork = wi;
}
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(remainingWork.getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(processInstance);
assertEquals(13, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("and1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Koniec"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor 3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("HT Form4"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("xor4"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Koniec2"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("or1"));
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveParallelExclusiveSplitNoLoopAsync.
@Test
public void testInclusiveParallelExclusiveSplitNoLoopAsync() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveNestedInParallelNestedInExclusive.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", new SystemOutWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Integer x = (Integer) workItem.getParameter("input1");
x++;
Map<String, Object> results = new HashMap<String, Object>();
results.put("output1", x);
manager.completeWorkItem(workItem.getId(), results);
}
});
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 0);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
// complete work items within OR gateway
for (WorkItem workItem : workItems) {
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
assertProcessInstanceActive(processInstance);
workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(1, workItems.size());
// complete last workitem after AND gateway
for (WorkItem workItem : workItems) {
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
assertProcessInstanceCompleted(processInstance);
assertEquals(12, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("ANDGateway-diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("ORGateway-diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI2"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ORGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ANDGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI6"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testMultipleEnabledOnSingleConditionalSequenceFlow.
@Test
public void testMultipleEnabledOnSingleConditionalSequenceFlow() throws Exception {
System.setProperty("jbpm.enable.multi.con", "true");
KieBase kbase = createKnowledgeBase("BPMN2-MultiConnEnabled.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterNodeTriggered(org.kie.api.event.process.ProcessNodeTriggeredEvent event) {
if ("Task2".equals(event.getNodeInstance().getNodeName())) {
list.add(event.getNodeInstance().getNodeId());
}
}
});
assertEquals(0, list.size());
ProcessInstance processInstance = ksession.startProcess("BPMN2-MultiConnEnabled");
assertProcessInstanceActive(processInstance);
ksession.signalEvent("signal", null, processInstance.getId());
assertProcessInstanceCompleted(processInstance);
assertEquals(1, list.size());
System.clearProperty("jbpm.enable.multi.con");
}
Aggregations