use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method compensationViaCancellation.
@Test
@Ignore
public void compensationViaCancellation() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-IntermediateThrowEvent.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "0");
ProcessInstance processInstance = ksession.startProcess("CompensateIntermediateThrowEvent", params);
ksession.signalEvent("Cancel", null, processInstance.getId());
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
// compensation activity (assoc. with script task) signaled *after* script task
assertProcessInstanceCompleted(processInstance.getId(), ksession);
assertProcessVarValue(processInstance, "x", "1");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method specificCompensationOfASubProcess.
@Test
public void specificCompensationOfASubProcess() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-ThrowSpecificForSubProcess.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 1);
ProcessInstance processInstance = ksession.startProcess("CompensationSpecificSubProcess", params);
// compensation activity (assoc. with script task) signaled *after* to-compensate script task
assertProcessInstanceCompleted(processInstance.getId(), ksession);
if (!isPersistence()) {
assertProcessVarValue(processInstance, "x", null);
} else {
String actualValue = getProcessVarValue(processInstance, "x");
assertThat(actualValue, AnyOf.anyOf(Is.is(""), Is.is(" "), Is.is((String) null)));
}
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method orderedCompensation.
@Test
public void orderedCompensation() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-ParallelOrderedCompensation-IntermediateThrowEvent.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "");
ProcessInstance processInstance = ksession.startProcess("CompensateParallelOrdered", params);
List<WorkItem> workItems = workItemHandler.getWorkItems();
List<Long> workItemIds = new ArrayList<Long>();
for (WorkItem workItem : workItems) {
if ("Thr".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (WorkItem workItem : workItems) {
if ("Two".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (WorkItem workItem : workItems) {
if ("One".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (Long id : workItemIds) {
ksession.getWorkItemManager().completeWorkItem(id, null);
}
// user task -> script task (associated with compensation) --> intermeidate throw compensation event
String xVal = getProcessVarValue(processInstance, "x");
// Compensation happens in the *REVERSE* order of completion
// Ex: if the order is 3, 17, 282, then compensation should happen in the order of 282, 17, 3
// Compensation did not fire in the same order as the associated activities completed.
Assertions.assertThat(xVal).isEqualTo("_171:_131:_141:_151:");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method compensationTwiceViaSignal.
@Test
public void compensationTwiceViaSignal() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-IntermediateThrowEvent.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "0");
String processId = "CompensateIntermediateThrowEvent";
ProcessInstance processInstance = ksession.startProcess(processId, params);
// twice
ksession.signalEvent("Compensation", CompensationScope.IMPLICIT_COMPENSATION_PREFIX + processId, processInstance.getId());
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
// compensation activity (assoc. with script task) signaled *after* script task
assertProcessInstanceCompleted(processInstance.getId(), ksession);
assertProcessVarValue(processInstance, "x", "2");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method compensationInSubSubProcesses.
@Test
public void compensationInSubSubProcesses() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-InSubSubProcess.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "0");
ProcessInstance processInstance = ksession.startProcess("CompensateSubSubSub", params);
ksession.signalEvent("Compensation", "_C-2", processInstance.getId());
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
// compensation activity (assoc. with script task) signaled *after* script task
assertProcessInstanceCompleted(processInstance.getId(), ksession);
assertProcessVarValue(processInstance, "x", "2");
}
Aggregations