use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessMessage.
@Test
public void testEventSubprocessMessage() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessMessage.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-EventSubprocessMessage");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("Message-HelloMessage", null, processInstance.getId());
ksession.signalEvent("Message-HelloMessage", null);
ksession.signalEvent("Message-HelloMessage", null);
ksession.signalEvent("Message-HelloMessage", null);
ksession.getProcessInstance(processInstance.getId());
ksession.getProcessInstance(processInstance.getId());
ksession.getProcessInstance(processInstance.getId());
ksession.getProcessInstance(processInstance.getId());
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(4);
}
use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessMessageWithLocalVars.
@Test(timeout = 10000)
public void testEventSubprocessMessageWithLocalVars() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("subprocess/BPMN2-EventSubProcessWithLocalVariables.bpmn2");
final Set<String> variablevalues = new HashSet<String>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
@SuppressWarnings("unchecked") Map<String, String> variable = (Map<String, String>) event.getNodeInstance().getVariable("richiesta");
if (variable != null) {
variablevalues.addAll(variable.keySet());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("EventSPWithVars");
assertProcessInstanceActive(processInstance);
Map<String, String> data = new HashMap<String, String>();
ksession.signalEvent("Message-MAIL", data, processInstance.getId());
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertThat(processInstance).isNull();
assertThat(variablevalues.size()).isEqualTo(2);
assertThat(variablevalues.contains("SCRIPT1")).isTrue();
assertThat(variablevalues.contains("SCRIPT2")).isTrue();
}
use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessSignalInterrupting.
@Test
public void testEventSubprocessSignalInterrupting() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessSignalInterrupting.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-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("MySignal", null, processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubprocessError.
@Test
public void testEventSubprocessError() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.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-EventSubprocessError");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
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");
assertEquals(1, executednodes.size());
}
use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubprocessErrorWithOutErrorCode.
@Test
public void testEventSubprocessErrorWithOutErrorCode() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/EventSubprocessErrorHandlingWithOutErrorCode.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script2")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
ProcessInstance processInstance = ksession.startProcess("order-fulfillment-bpm.ccc");
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "Script1", "starterror", "Script2", "end2", "eventsubprocess");
assertProcessVarValue(processInstance, "CapturedException", "java.lang.RuntimeException: XXX");
assertEquals(1, executednodes.size());
}
Aggregations