use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testThrowIntermediateSignalWithExternalScope.
@Test
public void testThrowIntermediateSignalWithExternalScope() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventExternalScope.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
WorkItemHandler externalHandler = new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String signal = (String) workItem.getParameter("Signal");
ksession.signalEvent(signal, null);
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
};
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.getWorkItemManager().registerWorkItemHandler("External Send Task", externalHandler);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("intermediate-event-scope", params);
assertProcessInstanceActive(processInstance);
assertNodeActive(processInstance.getId(), ksession, "Complete work", "Wait");
List<WorkItem> items = handler.getWorkItems();
assertThat(items.size()).isEqualTo(1);
WorkItem wi = items.get(0);
Map<String, Object> result = new HashMap<String, Object>();
result.put("_output", "sending event");
ksession.getWorkItemManager().completeWorkItem(wi.getId(), result);
assertProcessInstanceCompleted(processInstance);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessTimer.
@Test(timeout = 10000)
public void testEventSubprocessTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Script Task 1", 1);
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessTimer.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessTimer");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
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");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventBasedSplitWithCronTimerAndSignal.
@Test(timeout = 10000)
public void testEventBasedSplitWithCronTimerAndSignal() throws Exception {
System.setProperty("jbpm.enable.multi.con", "true");
try {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Request photos of order in use", 1);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Send a thank you card", 1);
NodeLeftCountDownProcessEventListener countDownListener4 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
KieBase kbase = createKnowledgeBase("timer/BPMN2-CronTimerWithEventBasedGateway.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(countDownListener);
ksession.addEventListener(countDownListener2);
ksession.addEventListener(countDownListener3);
ksession.addEventListener(countDownListener4);
ProcessInstance processInstance = ksession.startProcess("timerWithEventBasedGateway");
assertProcessInstanceActive(processInstance.getId(), ksession);
countDownListener.waitTillCompleted();
logger.debug("First timer triggered");
countDownListener2.waitTillCompleted();
logger.debug("Second timer triggered");
countDownListener3.waitTillCompleted();
logger.debug("Third timer triggered");
countDownListener4.waitTillCompleted();
logger.debug("Fourth timer triggered");
List<WorkItem> wi = handler.getWorkItems();
assertThat(wi).isNotNull();
assertThat(wi.size()).isEqualTo(3);
ksession.abortProcessInstance(processInstance.getId());
} finally {
// clear property only as the only relevant value is when it's set to true
System.clearProperty("jbpm.enable.multi.con");
}
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testSignalBoundaryEventOnTaskComplete.
@Test
public void testSignalBoundaryEventOnTaskComplete() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(LOGGING_EVENT_LISTENER);
ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
ksession.signalEvent("MySignal", "value");
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessSignalWithTransformation.
@Test
public void testEventSubprocessSignalWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-EventSubprocessSignalWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.signalEvent("MySignal", "john", processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "end-sub");
String var = getProcessVarValue(processInstance, "x");
assertThat(var).isNotNull();
assertThat(var).isEqualTo("JOHN");
}
Aggregations