use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessMessageWithLocalVars.
@Test(timeout = 10000)
public void testEventSubprocessMessageWithLocalVars() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("subprocess/BPMN2-EventSubProcessWithLocalVariables.bpmn2");
final Set<String> variablevalues = new HashSet<String>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@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());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("EventSPWithVars");
assertProcessInstanceActive(processInstance);
Map<String, String> data = new HashMap<String, String>();
ksession.signalEvent("Message-MAIL", data, processInstance.getId());
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertThat(processInstance).isNull();
assertThat(variablevalues.size()).isEqualTo(2);
assertThat(variablevalues.contains("SCRIPT1")).isTrue();
assertThat(variablevalues.contains("SCRIPT2")).isTrue();
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessSignalInterrupting.
@Test
public void testEventSubprocessSignalInterrupting() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessSignalInterrupting.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("MySignal", null, processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonProcessViolatedWithExpression.
@Test
public void testSLAonProcessViolatedWithExpression() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
final ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
latch.countDown();
}
};
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAExpr.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.addEventListener(listener);
Map<String, Object> parameters = new HashMap<>();
parameters.put("s", "3s");
ProcessInstance processInstance = ksession.startProcess("UserTask", parameters);
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();
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonUserTaskViolatedExternalTracking.
@Test
public void testSLAonUserTaskViolatedExternalTracking() 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);
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);
Collection<NodeInstance> active = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertEquals(1, active.size());
NodeInstance userTaskNode = active.iterator().next();
// simulate external tracking of sla
ksession.signalEvent("slaViolation:" + userTaskNode.getId(), null, processInstance.getId());
slaViolated = latch.await(10, TimeUnit.SECONDS);
assertTrue("SLA was not violated while it is expected", slaViolated);
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();
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubprocessError.
@Test
public void testEventSubprocessError() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertEquals(1, executednodes.size());
}
Aggregations