use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ErrorEventTest method testEventSubprocessErrorWithErrorCode.
@Test
public void testEventSubprocessErrorWithErrorCode() throws Exception {
kruntime = createKogitoProcessRuntime("subprocess/EventSubprocessErrorHandlingWithErrorCode.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script2")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
KogitoProcessInstance processInstance = kruntime.startProcess("order-fulfillment-bpm.ccc");
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "start", "Script1", "starterror", "Script2", "end2", "eventsubprocess");
assertProcessVarValue(processInstance, "CapturedException", "java.lang.RuntimeException: XXX");
assertEquals(1, executednodes.size());
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ErrorEventTest method testEventSubprocessError.
@Test
public void testEventSubprocessError() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessError.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessError");
assertProcessInstanceActive(processInstance);
kruntime.getProcessEventManager().addEventListener(listener);
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertEquals(1, executednodes.size());
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ErrorEventTest method testEventSubprocessErrorThrowOnTask.
@Test
public void testEventSubprocessErrorThrowOnTask() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessError.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {
@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
throw new MyError();
}
@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
manager.abortWorkItem(workItem.getStringId());
}
});
KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessError");
assertProcessInstanceFinished(processInstance, kruntime);
assertProcessInstanceAborted(processInstance);
assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertEquals(1, executednodes.size());
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SignalEventIT method testIntermediateEndSignal.
@Test
public void testIntermediateEndSignal() throws Exception {
Application app = generateCode(Collections.singletonMap(TYPE.PROCESS, Collections.singletonList("signalevent/EndEventSignalWithData.bpmn2")));
KogitoProcessEventListener listener = mock(KogitoProcessEventListener.class);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("src.simpleEndSignal");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
ArgumentCaptor<SignalEvent> signalEvent = ArgumentCaptor.forClass(SignalEvent.class);
verify(listener).onSignal(signalEvent.capture());
assertThat(signalEvent.getValue().getSignalName()).isEqualTo("Signal1");
assertThat(signalEvent.getValue().getSignal()).isEqualTo("Some value");
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SignalEventIT method testIntermediateThrowSignal.
@Test
public void testIntermediateThrowSignal() throws Exception {
Application app = generateCode(Collections.singletonMap(TYPE.PROCESS, Collections.singletonList("signalevent/IntermediateThrowEventSignal.bpmn2")));
KogitoProcessEventListener listener = mock(KogitoProcessEventListener.class);
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("IntermediateThrowEventSignal");
Model m = p.createModel();
m.update(Collections.singletonMap("x", "Javierito"));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
ArgumentCaptor<SignalEvent> signalEvent = ArgumentCaptor.forClass(SignalEvent.class);
verify(listener).onSignal(signalEvent.capture());
assertThat(signalEvent.getValue().getSignalName()).isEqualTo("MySignal");
assertThat(signalEvent.getValue().getSignal()).isEqualTo("Javierito");
}
Aggregations