use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testMultiInstanceLoopNumberTest.
@Test
public void testMultiInstanceLoopNumberTest() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoop-Numbering.bpmn2");
ksession = createKnowledgeSession(kbase);
Map<String, Object> params = new HashMap<String, Object>();
final Map<String, String> nodeIdNodeNameMap = new HashMap<String, String>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
NodeInstance nodeInstance = event.getNodeInstance();
String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId();
String nodeName = ((NodeInstanceImpl) nodeInstance).getNode().getName();
String prevNodeName = nodeIdNodeNameMap.put(uniqId, nodeName);
if (prevNodeName != null) {
assertEquals(uniqId + " is used for more than one node instance: ", prevNodeName, nodeName);
}
}
});
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("Test.MultipleInstancesBug", params);
List<WorkItem> workItems = handler.getWorkItems();
logger.debug("COMPLETING TASKS.");
ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
assertProcessInstanceCompleted(processInstance);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testMultipleGatewaysProcess.
@Test
public void testMultipleGatewaysProcess() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultipleGatewaysProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new DefaultProcessEventListener() {
ProcessInstance pi;
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("CreateAgent")) {
pi.signalEvent("Signal_1", null);
}
}
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info("Before Node triggered event received for node: {}", event.getNodeInstance().getNodeName());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
pi = event.getProcessInstance();
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("action", "CreateAgent");
ProcessInstance processInstance = ksession.startProcess("multiplegateways", params);
assertProcessInstanceCompleted(processInstance);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitWithLoopInsideSubprocess.
@Test
public void testInclusiveSplitWithLoopInsideSubprocess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInsideSubprocess.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();
TestWorkItemHandler handler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", -1);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().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("Sub Process 1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-end"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitWithLoopInside.
@Test
public void testInclusiveSplitWithLoopInside() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInside.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();
TestWorkItemHandler handler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", -1);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(processInstance);
assertEquals(10, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testSubProcessWithTypeVariable.
@Test
public void testSubProcessWithTypeVariable() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/BPMN2-SubProcessWithTypeVariable.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<String> list = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Read Map")) {
list.add(event.getNodeInstance().getNodeName());
}
}
});
ProcessInstance processInstance = ksession.startProcess("sub_variable.sub_variables");
assertProcessInstanceCompleted(processInstance);
assertEquals(2, list.size());
}
Aggregations