Search in sources :

Example 1 with ForEachJoinNodeInstance

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);
    }
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ForEachJoinNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) ForEachJoinNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)1 ForEachNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance)1 ForEachJoinNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkItem (org.kie.api.runtime.process.WorkItem)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1