Search in sources :

Example 61 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ActivityTest method testAdHocSubProcessAutoCompleteDynamicSubProcess.

@Test
public void testAdHocSubProcessAutoCompleteDynamicSubProcess() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl", "BPMN2-MinimalProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession.fireAllRules();
    DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
    DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, "Minimal", new HashMap<String, Object>());
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    // assertProcessInstanceActive(processInstance.getId(), ksession);
    // workItem = workItemHandler2.getWorkItem();
    // ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) 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 62 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ActivityTest method testAdHocSubProcessAutoComplete.

@Test
public void testAdHocSubProcessAutoComplete() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.fireAllRules();
    workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertEquals("Exit", getProcessVarValue(processInstance, "y"));
    assertProcessInstanceFinished(processInstance, ksession);
}
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) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 63 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ActivityTest method testAdHocSubProcessAutoCompleteDynamicTask.

@Test
public void testAdHocSubProcessAutoCompleteDynamicTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
    DynamicUtils.addDynamicWorkItem(dynamicContext, ksession, "OtherTask", new HashMap<String, Object>());
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.fireAllRules();
    workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceActive(processInstance);
    workItem = workItemHandler2.getWorkItem();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) 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 64 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ActivityTest method testUserTaskWithBooleanOutput.

@Test
public void testUserTaskWithBooleanOutput() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithBooleanOutput.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("com.sample.boolean");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    HashMap<String, Object> output = new HashMap<String, Object>();
    output.put("isCheckedCheckbox", "true");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), output);
    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 65 with WorkItem

use of org.kie.api.runtime.process.WorkItem 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)

Aggregations

WorkItem (org.kie.api.runtime.process.WorkItem)174 Test (org.junit.Test)139 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)127 KieBase (org.kie.api.KieBase)110 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)91 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)87 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)48 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)33 ArrayList (java.util.ArrayList)29 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)26 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)22 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)14 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 Map (java.util.Map)11 StringReader (java.io.StringReader)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)10