Search in sources :

Example 96 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessViolatedWithExpression.

@Test
public void testSLAonProcessViolatedWithExpression() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLAExpr.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("s", "3s");
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask", parameters);
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) Test(org.junit.jupiter.api.Test)

Example 97 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonUserTaskViolatedExternalTracking.

@Test
public void testSLAonUserTaskViolatedExternalTracking() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLAOnTask.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false");
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
    assertFalse(slaViolated, "SLA should not violated by timer");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance userTaskNode = active.iterator().next();
    // simulate external tracking of sla
    kruntime.signalEvent("slaViolation:" + userTaskNode.getStringId(), null, processInstance.getStringId());
    slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Example 98 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessMet.

@Test
public void testSLAonProcessMet() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLA.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_MET, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 99 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessViolatedNoTracking.

@Test
public void testSLAonProcessViolatedNoTracking() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLA.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false");
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
    assertFalse(slaViolated, "SLA should not violated by timer");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_PENDING, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 100 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project kogito-runtimes by kiegroup.

the class StartEventTest method testMultipleEventBasedStartEventsSignalDifferentPaths.

@Test
public void testMultipleEventBasedStartEventsSignalDifferentPaths() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-MultipleStartEventProcessDifferentPaths.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<String> list = new ArrayList<>();
    kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
        }
    });
    kruntime.signalEvent("startSignal", null);
    assertThat(list.size()).isEqualTo(1);
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    String processInstanceId = ((KogitoWorkItemImpl) workItem).getProcessInstanceStringId();
    KogitoProcessInstance processInstance = kruntime.getProcessInstance(processInstanceId);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstanceId, "StartSignal", "Script 3", "User task", "End");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Test(org.junit.jupiter.api.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