Search in sources :

Example 51 with TestWorkItemHandler

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

the class CompensationTest method compensationViaIntermediateThrowEventProcess.

/**
 * TESTS
 */
@Test
public void compensationViaIntermediateThrowEventProcess() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-IntermediateThrowEvent.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "0");
    ProcessInstance processInstance = ksession.startProcess("CompensateIntermediateThrowEvent", params);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    // compensation activity (assoc. with script task) signaled *after* script task
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessVarValue(processInstance, "x", "1");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 52 with TestWorkItemHandler

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

the class StandaloneBPMNProcessTest method testAdHocSubProcess.

@Test
@Ignore("Process does not complete.")
public void testAdHocSubProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-AdHocSubProcess.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNull();
    ksession = restoreSession(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.fireAllRules();
    ksession.signalEvent("Hello2", null, processInstance.getId());
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession = restoreSession(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with TestWorkItemHandler

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

the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.

@Test
public void testMultipleEventBasedStartEventsSignalStart() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<Long> list = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    ksession.signalEvent("startSignal", null);
    assertThat(list.size()).isEqualTo(1);
    WorkItem workItem = workItemHandler.getWorkItem();
    long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    ksession = restoreSession(ksession, true);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 54 with TestWorkItemHandler

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

the class StartEventTest method testMultipleStartEventsRegularStart.

@Test
public void testMultipleStartEventsRegularStart() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleStartEventProcessLongInterval.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("MultipleStartEvents");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 55 with TestWorkItemHandler

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

the class StartEventTest method testSignalToStartProcess.

@Test
public void testSignalToStartProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2", "BPMN2-IntermediateThrowEventSignal.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    final List<String> startedProcesses = new ArrayList<String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            startedProcesses.add(event.getProcessInstance().getProcessId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("SignalIntermediateEvent");
    assertProcessInstanceFinished(processInstance, ksession);
    assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
    assertThat(getNumberOfProcessInstances("SignalIntermediateEvent")).isEqualTo(1);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) 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