Search in sources :

Example 21 with TestWorkItemHandler

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

the class ActivityTest method testCallActivityWithContantsAssignment.

@Test
public void testCallActivityWithContantsAssignment() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/SingleTaskWithVarDef.bpmn2", "subprocess/InputMappingUsingValue.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("CustomTask", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("defaultPackage.InputMappingUsingValue", params);
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    Object value = workItem.getParameter("TaskName");
    assertNotNull(value);
    assertEquals("test string", value);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance);
}
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 22 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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 23 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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 24 with TestWorkItemHandler

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

the class SLAComplianceTest method testSLAonUserTaskViolated.

@Test
public void testSLAonUserTaskViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAOnTask.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.addEventListener(listener);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue("SLA was not violated while it is expected", slaViolated);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_NA, slaCompliance);
    Collection<NodeInstance> active = ((WorkflowProcessInstance) processInstance).getNodeInstances();
    assertEquals(1, active.size());
    NodeInstance userTaskNode = active.iterator().next();
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, NodeInstanceLog.TYPE_ENTER);
    assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, NodeInstanceLog.TYPE_EXIT);
    assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) CountDownLatch(java.util.concurrent.CountDownLatch) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 25 with TestWorkItemHandler

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

the class SLAComplianceTest method testSLAonProcessViolated.

@Test
public void testSLAonProcessViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.addEventListener(listener);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue("SLA was not violated while it is expected", slaViolated);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance);
    ksession.dispose();
}
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) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) CountDownLatch(java.util.concurrent.CountDownLatch) WorkItem(org.kie.api.runtime.process.WorkItem) 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