Search in sources :

Example 26 with WorkItem

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

the class SLAComplianceTest method testSLAonProcessViolatedNoTracking.

@Test
public void testSLAonProcessViolatedNoTracking() 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);
    ksession.getEnvironment().set("SLATimerMode", "false");
    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(5, TimeUnit.SECONDS);
    assertFalse("SLA should not violated by timer", slaViolated);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_PENDING, 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)

Example 27 with WorkItem

use of org.kie.api.runtime.process.WorkItem 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);
    Collection<NodeInstance> active = ((WorkflowProcessInstance) processInstance).getNodeInstances();
    assertEquals(1, active.size());
    NodeInstance userTaskNode = active.iterator().next();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode);
    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) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 28 with WorkItem

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

Example 29 with WorkItem

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

the class SLAComplianceTest method testSLAonProcessViolatedExternalTracking.

@Test
public void testSLAonProcessViolatedExternalTracking() 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);
    ksession.getEnvironment().set("SLATimerMode", "false");
    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(5, TimeUnit.SECONDS);
    assertFalse("SLA should not violated by timer", slaViolated);
    // simulate external tracking of sla
    ksession.signalEvent("slaViolation", null, processInstance.getId());
    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)

Example 30 with WorkItem

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

the class StandaloneBPMNProcessTest method testLane.

@Test
public void testLane() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-Lane.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("ActorId", "mary");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("SwimlaneActorId")).isEqualTo("mary");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) 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) 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