use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonUserTaskViolated.
@Test
public void testSLAonUserTaskViolated() 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);
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(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_NA, slaCompliance);
Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
assertEquals(1, active.size());
KogitoNodeInstance userTaskNode = active.iterator().next();
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonProcessViolatedExternalTracking.
@Test
public void testSLAonProcessViolatedExternalTracking() 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");
// simulate external tracking of sla
kruntime.signalEvent("slaViolation", null, processInstance.getStringId());
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);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonProcessViolated.
@Test
public void testSLAonProcessViolated() 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);
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(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);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonCatchEventViolated.
@Test
public void testSLAonCatchEventViolated() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
latch.countDown();
}
};
kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignalWithSLAOnEvent.bpmn2");
kruntime.getProcessEventManager().addEventListener(listener);
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
assertTrue(slaViolated, "SLA should be 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 eventNode = active.iterator().next();
kruntime.signalEvent("MyMessage", null, processInstance.getStringId());
assertProcessInstanceFinished(processInstance, kruntime);
int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 0);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 1);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class IntermediateEventTest method testEventSubprocessConditional.
@Test
public void testEventSubprocessConditional() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessConditional.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessConditional");
assertProcessInstanceActive(processInstance);
Person person = new Person();
person.setName("john");
kruntime.getKieSession().insert(person);
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(1);
}
Aggregations