use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testLane.
@Test
public void testLane() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-Lane.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
Map<String, Object> results = new HashMap<String, Object>();
results.put("ActorId", "mary");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("SwimlaneActorId")).isEqualTo("mary");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.
@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
if (workItem.getParameter("ActorId").equals("mary")) {
throw new MyError();
}
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.abortWorkItem(workItem.getId());
}
});
ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
assertProcessInstanceActive(processInstance);
assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testErrorBoundaryEventOnExit.
@Test
public void testErrorBoundaryEventOnExit() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnExitException.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnExit");
assertProcessInstanceActive(processInstance.getId(), ksession);
WorkItem workItem = handler.getWorkItem();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(1, handler.getWorkItems().size());
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class EscalationEventTest method testEscalationBoundaryEventInterruptsTask.
@Test
@Ignore("Escalation does not cancel work items yet.")
public // TODO: make escalation interrupt tasks -- or look more closely at the spec to make sure that's the case?
void testEscalationBoundaryEventInterruptsTask() throws Exception {
KieBase kbase = createKnowledgeBase("escalation/BPMN2-EscalationBoundaryEventInterrupting.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("MyTask", handler);
ProcessInstance processInstance = ksession.startProcess("EscalationBoundaryEvent");
assertProcessInstanceCompleted(processInstance);
// Check for cancellation of task
assertEquals("WorkItem was not cancelled!", WorkItem.ABORTED, handler.getWorkItem().getState());
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitAndJoin.
@Test
public void testInclusiveSplitAndJoin() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoin.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 15);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();
assertEquals(2, activeWorkItems.size());
ksession = restoreSession(ksession, true);
for (WorkItem wi : activeWorkItems) {
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceFinished(processInstance, ksession);
}
Aggregations