Search in sources :

Example 1 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class CompensationTest method orderedCompensation.

@Test
public void orderedCompensation() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-ParallelOrderedCompensation-IntermediateThrowEvent.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "");
    ProcessInstance processInstance = ksession.startProcess("CompensateParallelOrdered", params);
    List<WorkItem> workItems = workItemHandler.getWorkItems();
    List<Long> workItemIds = new ArrayList<Long>();
    for (WorkItem workItem : workItems) {
        if ("Thr".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getId());
        }
    }
    for (WorkItem workItem : workItems) {
        if ("Two".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getId());
        }
    }
    for (WorkItem workItem : workItems) {
        if ("One".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getId());
        }
    }
    for (Long id : workItemIds) {
        ksession.getWorkItemManager().completeWorkItem(id, null);
    }
    // user task -> script task (associated with compensation) --> intermeidate throw compensation event
    String xVal = getProcessVarValue(processInstance, "x");
    // Compensation happens in the *REVERSE* order of completion
    // Ex: if the order is 3, 17, 282, then compensation should happen in the order of 282, 17, 3
    // Compensation did not fire in the same order as the associated activities completed.
    Assertions.assertThat(xVal).isEqualTo("_171:_131:_141:_151:");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 2 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class CompensationTest method compensationViaCancellation.

@Test
@Ignore
public void compensationViaCancellation() 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.signalEvent("Cancel", null, processInstance.getId());
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class CompensationTest method compensationTwiceViaSignal.

@Test
public void compensationTwiceViaSignal() 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");
    String processId = "CompensateIntermediateThrowEvent";
    ProcessInstance processInstance = ksession.startProcess(processId, params);
    // twice
    ksession.signalEvent("Compensation", CompensationScope.IMPLICIT_COMPENSATION_PREFIX + processId, processInstance.getId());
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    // compensation activity (assoc. with script task) signaled *after* script task
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessVarValue(processInstance, "x", "2");
}
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 4 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class CompensationTest method specificCompensationOfASubProcess.

@Test
public void specificCompensationOfASubProcess() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-ThrowSpecificForSubProcess.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 1);
    ProcessInstance processInstance = ksession.startProcess("CompensationSpecificSubProcess", params);
    // compensation activity (assoc. with script task) signaled *after* to-compensate script task
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    if (!isPersistence()) {
        assertProcessVarValue(processInstance, "x", null);
    } else {
        // We need to check it this way because of some databases like Oracle RAC etc.
        List<VariableInstanceLog> logs = logService.findVariableInstances(processInstance.getId(), "x");
        List<String> values = logs.stream().map(VariableInstanceLog::getValue).collect(Collectors.toList());
        assertThat(values, IsCollectionContaining.hasItem(AnyOf.anyOf(Is.is(" "), Is.is(""), Is.is((String) null))));
    }
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 5 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class CompensationTest method compensationInSubSubProcesses.

@Test
public void compensationInSubSubProcesses() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-InSubSubProcess.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("CompensateSubSubSub", params);
    ksession.signalEvent("Compensation", "_C-2", processInstance.getId());
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    // compensation activity (assoc. with script task) signaled *after* script task
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessVarValue(processInstance, "x", "2");
}
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)

Aggregations

TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)307 HashMap (java.util.HashMap)172 Test (org.junit.Test)154 Test (org.junit.jupiter.api.Test)151 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)149 KieBase (org.kie.api.KieBase)147 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)139 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)108 WorkItem (org.kie.api.runtime.process.WorkItem)103 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)94 ArrayList (java.util.ArrayList)54 KieSession (org.kie.api.runtime.KieSession)43 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)34 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)32 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)25 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener)24 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)23 Person (org.jbpm.bpmn2.objects.Person)21 Disabled (org.junit.jupiter.api.Disabled)20 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)18