Search in sources :

Example 16 with TestWorkItemHandler

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

the class StandaloneBPMNProcessTest method testLane.

@Test
public void testLane() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-Lane.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("ActorId", "mary");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("SwimlaneActorId")).isEqualTo("mary");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) 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 17 with TestWorkItemHandler

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

the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.

@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            if (workItem.getParameter("ActorId").equals("mary")) {
                throw new MyError();
            }
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
    assertProcessInstanceActive(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) 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) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 18 with TestWorkItemHandler

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

the class ErrorEventTest method testErrorBoundaryEventOnExit.

@Test
public void testErrorBoundaryEventOnExit() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnExitException.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnExit");
    assertProcessInstanceActive(processInstance.getId(), ksession);
    WorkItem workItem = handler.getWorkItem();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    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) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 19 with TestWorkItemHandler

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

the class EscalationEventTest method testEscalationBoundaryEventInterruptsTask.

@Test
@Ignore("Escalation does not cancel work items yet.")
public // TODO: make escalation interrupt tasks -- or look more closely at the spec to make sure that's the case?
void testEscalationBoundaryEventInterruptsTask() throws Exception {
    KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventInterrupting.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", handler);
    ProcessInstance processInstance = ksession.startProcess("EscalationBoundaryEvent");
    assertProcessInstanceCompleted(processInstance);
    // Check for cancellation of task
    assertEquals("WorkItem was not cancelled!", WorkItem.ABORTED, handler.getWorkItem().getState());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with TestWorkItemHandler

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

the class FlowTest method testInclusiveSplitAndJoin.

@Test
public void testInclusiveSplitAndJoin() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoin.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", 15);
    ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
    List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();
    assertEquals(2, 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)

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