use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testMessageBoundaryEventOnTask.
@Test
public void testMessageBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundaryMessageEventOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("BoundaryMessageOnTask");
ksession.signalEvent("Message-HelloMessage", "message data");
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "StartProcess", "User Task", "Boundary event", "Condition met", "End2");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonProcessMet.
@Test
public void testSLAonProcessMet() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.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);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(ProcessInstance.SLA_MET, slaCompliance);
ksession.dispose();
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler 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.jbpm.bpmn2.objects.TestWorkItemHandler 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.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testAdHocSubProcessAutoComplete.
@Test
@Ignore("Process does not complete.")
public void testAdHocSubProcessAutoComplete() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-AdHocSubProcessAutoComplete.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNull();
ksession = restoreSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.fireAllRules();
workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull().withFailMessage("WorkItem should not be null.");
ksession = restoreSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Aggregations