Search in sources :

Example 11 with KogitoProcessEventListener

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());
}
Also used : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 12 with KogitoProcessEventListener

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());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 13 with KogitoProcessEventListener

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());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 14 with KogitoProcessEventListener

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");
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) SignalEvent(org.kie.api.event.process.SignalEvent) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 15 with KogitoProcessEventListener

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");
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) Model(org.kie.kogito.Model) SignalEvent(org.kie.api.event.process.SignalEvent) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)23 Test (org.junit.jupiter.api.Test)21 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)21 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)20 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)14 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)14 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)13 ArrayList (java.util.ArrayList)11 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)5 KogitoWorkflowProcessInstance (org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance)4 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)4 SignalEvent (org.kie.api.event.process.SignalEvent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 Application (org.kie.kogito.Application)2 EventDescription (org.kie.kogito.process.EventDescription)2 ProcessConfig (org.kie.kogito.process.ProcessConfig)2