Search in sources :

Example 26 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class FlowTest method testInclusiveSplitAndJoinExtraPath.

@Test
public void testInclusiveSplitAndJoinExtraPath() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoinExtraPath.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 25);
    ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
    ksession.signalEvent("signal", null);
    List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();
    assertEquals(4, activeWorkItems.size());
    ksession = restoreSession(ksession, true);
    for (int i = 0; i < 3; i++) {
        ksession.getWorkItemManager().completeWorkItem(activeWorkItems.get(i).getId(), null);
    }
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(activeWorkItems.get(3).getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 27 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class FlowTest method testInclusiveSplitAndJoinWithParallel.

@Test
public void testInclusiveSplitAndJoinWithParallel() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoinWithParallel.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 25);
    ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
    List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();
    assertEquals(4, activeWorkItems.size());
    ksession = restoreSession(ksession, true);
    for (WorkItem wi : activeWorkItems) {
        ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    }
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 28 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler 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"));
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class FlowTest method testMultiInstanceLoopCharacteristicsProcess2.

@Test
public void testMultiInstanceLoopCharacteristicsProcess2() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiInstanceProcessWithOutputOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> myList = new ArrayList<String>();
    List<String> myOutList = null;
    myList.add("John");
    myList.add("Mary");
    params.put("miinput", myList);
    ProcessInstance processInstance = ksession.startProcess("miprocess", params);
    List<WorkItem> workItems = handler.getWorkItems();
    assertNotNull(workItems);
    assertEquals(2, workItems.size());
    myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
    assertNull(myOutList);
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("reply", "Hello John");
    ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), results);
    myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
    assertNull(myOutList);
    results = new HashMap<String, Object>();
    results.put("reply", "Hello Mary");
    ksession.getWorkItemManager().completeWorkItem(workItems.get(1).getId(), results);
    myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
    assertNotNull(myOutList);
    assertEquals(2, myOutList.size());
    assertTrue(myOutList.contains("Hello John"));
    assertTrue(myOutList.contains("Hello Mary"));
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) Test(org.junit.Test)

Example 30 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class IntermediateEventTest method testConditionalBoundaryEventOnTaskComplete.

@Test
public void testConditionalBoundaryEventOnTaskComplete() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryConditionalEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    Person person = new Person();
    person.setName("john");
    // as the node that boundary event is attached to has been completed insert will not have any effect
    ksession.insert(person);
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "User Task2", "End1");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Aggregations

TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)141 Test (org.junit.Test)138 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)134 KieBase (org.kie.api.KieBase)131 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)96 WorkItem (org.kie.api.runtime.process.WorkItem)91 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)37 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)23 ArrayList (java.util.ArrayList)21 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)14 StartEventTest (org.jbpm.bpmn2.StartEventTest)13 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)10 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)8 Person (org.jbpm.bpmn2.objects.Person)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)8 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)7 CountDownLatch (java.util.concurrent.CountDownLatch)6