Search in sources :

Example 91 with TestWorkItemHandler

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

the class EndEventTest method testMessageEndVerifyDeploymentId.

@Test
public void testMessageEndVerifyDeploymentId() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MessageEndEvent.bpmn2");
    TestWorkItemHandler handler = new TestWorkItemHandler();
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Send Task", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "MyValue");
    ProcessInstance processInstance = ksession.startProcess("MessageEndEvent", params);
    assertProcessInstanceCompleted(processInstance);
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
    long nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
    long nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
    String deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
    assertNotNull(nodeId);
    assertTrue(nodeId > 0);
    assertNotNull(nodeInstanceId);
    assertTrue(nodeInstanceId > 0);
    assertNull(deploymentId);
    // now set deployment id as part of ksession's env
    ksession.getEnvironment().set("deploymentId", "testDeploymentId");
    processInstance = ksession.startProcess("MessageEndEvent", params);
    assertProcessInstanceCompleted(processInstance);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
    nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
    nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
    deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
    assertNotNull(nodeId);
    assertTrue(nodeId > 0);
    assertNotNull(nodeInstanceId);
    assertTrue(nodeInstanceId > 0);
    assertNotNull(deploymentId);
    assertEquals("testDeploymentId", deploymentId);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 92 with TestWorkItemHandler

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

the class ErrorEventTest method testErrorBoundaryEventOnTask.

@Test
public void testErrorBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
    List<WorkItem> workItems = handler.getWorkItems();
    assertEquals(2, workItems.size());
    WorkItem workItem = workItems.get(0);
    if (!"john".equalsIgnoreCase((String) workItem.getParameter("ActorId"))) {
        workItem = workItems.get(1);
    }
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertProcessInstanceAborted(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "error end event");
    assertNotNodeTriggered(processInstance.getId(), "Script Task", "error1", "error2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 93 with TestWorkItemHandler

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

the class ErrorEventTest method testEventSubprocessError.

@Test
public void testEventSubprocessError() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.bpmn2");
    final List<Long> executednodes = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(listener);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertEquals(1, executednodes.size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 94 with TestWorkItemHandler

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

the class ErrorEventTest method testErrorBoundaryEventOnEntry.

@Test
public void testErrorBoundaryEventOnEntry() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnEntryException.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnEntry");
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertEquals(1, handler.getWorkItems().size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 95 with TestWorkItemHandler

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

the class ErrorEventTest method testErrorBoundaryEventOnServiceTask.

@Test
public void testErrorBoundaryEventOnServiceTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("s", "test");
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnServiceTask", params);
    List<WorkItem> workItems = handler.getWorkItems();
    assertEquals(1, workItems.size());
    ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "Service task error attached", "end0", "Script Task", "error2");
    assertNotNodeTriggered(processInstance.getId(), "end");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) 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