use of org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance in project jbpm by kiegroup.
the class FlowTest method testMultiInstanceLoopCharacteristicsProcessWithORGateway.
@Test
public void testMultiInstanceLoopCharacteristicsProcessWithORGateway() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiInstanceLoopCharacteristicsProcessWithORgateway.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
List<Integer> myList = new ArrayList<Integer>();
myList.add(12);
myList.add(15);
params.put("list", myList);
ProcessInstance processInstance = ksession.startProcess("MultiInstanceLoopCharacteristicsProcess", params);
List<WorkItem> workItems = workItemHandler.getWorkItems();
assertEquals(4, workItems.size());
Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances();
assertEquals(1, nodeInstances.size());
NodeInstance nodeInstance = nodeInstances.iterator().next();
assertTrue(nodeInstance instanceof ForEachNodeInstance);
Collection<NodeInstance> nodeInstancesChild = ((ForEachNodeInstance) nodeInstance).getNodeInstances();
assertEquals(2, nodeInstancesChild.size());
for (NodeInstance child : nodeInstancesChild) {
assertTrue(child instanceof CompositeContextNodeInstance);
assertEquals(2, ((CompositeContextNodeInstance) child).getNodeInstances().size());
}
ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItems.get(1).getId(), null);
processInstance = ksession.getProcessInstance(processInstance.getId());
nodeInstances = ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances();
assertEquals(1, nodeInstances.size());
nodeInstance = nodeInstances.iterator().next();
assertTrue(nodeInstance instanceof ForEachNodeInstance);
if (isPersistence()) {
// when persistence is used there is slightly different behaviour of ContextNodeInstance
// it's already tested by SimplePersistenceBPMNProcessTest.testMultiInstanceLoopCharacteristicsProcessWithORGateway
nodeInstancesChild = ((ForEachNodeInstance) nodeInstance).getNodeInstances();
assertEquals(1, nodeInstancesChild.size());
Iterator<NodeInstance> childIterator = nodeInstancesChild.iterator();
assertTrue(childIterator.next() instanceof CompositeContextNodeInstance);
ksession.getWorkItemManager().completeWorkItem(workItems.get(2).getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItems.get(3).getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
} else {
nodeInstancesChild = ((ForEachNodeInstance) nodeInstance).getNodeInstances();
assertEquals(2, nodeInstancesChild.size());
Iterator<NodeInstance> childIterator = nodeInstancesChild.iterator();
assertTrue(childIterator.next() instanceof CompositeContextNodeInstance);
assertTrue(childIterator.next() instanceof ForEachJoinNodeInstance);
ksession.getWorkItemManager().completeWorkItem(workItems.get(2).getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItems.get(3).getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
}
Aggregations