use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testSignalBoundaryEventOnTask.
@Test
public void testSignalBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
ksession.addEventListener(LOGGING_EVENT_LISTENER);
ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
ksession.signalEvent("MySignal", "value");
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessConditional.
@Test
public void testEventSubprocessConditional() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessConditional.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessConditional");
assertProcessInstanceActive(processInstance);
Person person = new Person();
person.setName("john");
ksession.insert(person);
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");
assertThat(executednodes.size()).isEqualTo(1);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventSignalAndBoundarySignalEvent.
@Test
public void testIntermediateCatchEventSignalAndBoundarySignalEvent() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundaryEventWithSignals.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("boundaryeventtest");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
// now signal process instance
ksession.signalEvent("moveon", "", processInstance.getId());
assertProcessInstanceActive(processInstance);
WorkItem wi = handler.getWorkItem();
assertThat(wi).isNotNull();
// signal boundary event on user task
ksession.signalEvent("moveon", "", processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method runTestEventSubprocessSignal.
public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception {
KieBase kbase = createKnowledgeBase(processFile);
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("sub-script")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("MySignal", null, processInstance.getId());
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), completedNodes);
assertThat(executednodes.size()).isEqualTo(4);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testSignalBoundaryEventWithTransformation.
@Test
public void testSignalBoundaryEventWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn", "BPMN2-IntermediateThrowEventSignal.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "john");
ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");
ProcessInstance processInstance2 = ksession.startProcess("SignalIntermediateEvent", params);
assertProcessInstanceFinished(processInstance2, ksession);
assertProcessInstanceFinished(processInstance, ksession);
String var = getProcessVarValue(processInstance, "x");
assertThat(var).isEqualTo("JOHN");
}
Aggregations