use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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();
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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();
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonUserTaskMet.
@Test
public void testSLAonUserTaskMet() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAOnTask.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
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, NodeInstanceLog.TYPE_ENTER);
if (sessionPersistence) {
// In DB it is still seen as pending
assertEquals(ProcessInstance.SLA_PENDING, slaCompliance);
} else {
// Whereas in memory it is already met
assertEquals(ProcessInstance.SLA_MET, slaCompliance);
}
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, NodeInstanceLog.TYPE_EXIT);
assertEquals(ProcessInstance.SLA_MET, slaCompliance);
ksession.dispose();
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StartEventTest method testSignalToStartProcess.
@Test
public void testSignalToStartProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2", "BPMN2-IntermediateThrowEventSignal.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
final List<String> startedProcesses = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(event.getProcessInstance().getProcessId());
}
});
ProcessInstance processInstance = ksession.startProcess("SignalIntermediateEvent");
assertProcessInstanceFinished(processInstance, ksession);
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
assertThat(getNumberOfProcessInstances("SignalIntermediateEvent")).isEqualTo(1);
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.
@Test
public void testMultipleEventBasedStartEventsSignalStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("startSignal", null);
assertThat(list.size()).isEqualTo(1);
WorkItem workItem = workItemHandler.getWorkItem();
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
ksession = restoreSession(ksession, true);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
Aggregations