use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class IntermediateEventTest method testEventSubprocessMessageWithLocalVars.
@Test
@Timeout(10)
public void testEventSubprocessMessageWithLocalVars() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
kruntime = createKogitoProcessRuntime("subprocess/BPMN2-EventSubProcessWithLocalVariables.bpmn2");
final Set<String> variablevalues = new HashSet<String>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
@SuppressWarnings("unchecked") Map<String, String> variable = (Map<String, String>) event.getNodeInstance().getVariable("richiesta");
if (variable != null) {
variablevalues.addAll(variable.keySet());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
kruntime.getProcessEventManager().addEventListener(countDownListener);
KogitoProcessInstance processInstance = kruntime.startProcess("EventSPWithVars");
assertProcessInstanceActive(processInstance);
Map<String, String> data = new HashMap<>();
kruntime.signalEvent("Message-MAIL", data, processInstance.getStringId());
countDownListener.waitTillCompleted();
processInstance = kruntime.getProcessInstance(processInstance.getStringId());
assertThat(processInstance).isNull();
assertThat(variablevalues.size()).isEqualTo(2);
assertThat(variablevalues.contains("SCRIPT1")).isTrue();
assertThat(variablevalues.contains("SCRIPT2")).isTrue();
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ProcessFactoryTest method testBoundaryErrorEvent.
@Test
public void testBoundaryErrorEvent() throws Exception {
final String boundaryErrorEvent = "BoundaryErrorEvent";
final String errorCode = "java.lang.RuntimeException";
final String processId = "myProcess";
final RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess(processId);
final String startNode = "Start";
final String task = "Task";
final String endOnError = "EndOnError";
factory.name("My process").packageName("org.kie.kogito").startNode(1).name(startNode).metaData(UNIQUE_ID, startNode).done().workItemNode(2).name(task).workName(task).done().endNode(3).name("EndOnSuccess").done().boundaryEventNode(4).name(boundaryErrorEvent).attachedTo(2).metaData(ERROR_EVENT, errorCode).metaData(HAS_ERROR_EVENT, true).metaData(ERROR_STRUCTURE_REF, null).metaData("EventTpe", "error").metaData(UNIQUE_ID, boundaryErrorEvent).eventType("Error", errorCode).done().endNode(5).name(endOnError).metaData(UNIQUE_ID, endOnError).terminate(true).done().connection(1, 2).connection(2, 3).connection(4, 5);
final RuleFlowProcess process = factory.validate().getProcess();
Application application = mock(Application.class);
when(application.get(Processes.class)).thenReturn(new BpmnProcesses().addProcess(new BpmnProcess(process)));
final LightProcessRuntime processRuntime = LightProcessRuntime.of(application, Collections.singletonList(process), new LightProcessRuntimeServiceProvider());
processRuntime.getKogitoWorkItemManager().registerWorkItemHandler(task, new ExceptionOnPurposeHandler());
final List<String> completedNodes = new ArrayList<>();
final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
completedNodes.add(event.getNodeInstance().getNodeName());
super.afterNodeLeft(event);
}
};
processRuntime.addEventListener(listener);
ProcessInstance processInstance = processRuntime.startProcess(processId);
assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);
assertThat(completedNodes).contains(startNode, task, boundaryErrorEvent, endOnError);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener 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);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener 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);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonCatchEventNotViolated.
@Test
public void testSLAonCatchEventNotViolated() 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());
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, 1);
assertEquals(KogitoProcessInstance.SLA_MET, slaCompliance);
boolean slaViolated = latch.await(3, TimeUnit.SECONDS);
assertFalse(slaViolated, "SLA should not violated by timer");
}
Aggregations