Search in sources :

Example 21 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testEventSubprocessSignalInterrupting.

@Test
public void testEventSubprocessSignalInterrupting() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessSignalInterrupting.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-EventSubprocessSignal");
    assertProcessInstanceActive(processInstance);
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.signalEvent("MySignal", null, processInstance.getStringId());
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertThat(executednodes.size()).isEqualTo(1);
}
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) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 22 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testEventSubprocessSignalWithStateNode.

@Test
public void testEventSubprocessSignalWithStateNode() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessSignalWithStateNode.bpmn2");
    final List<String> executednodes = new ArrayList<>();
    KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("User Task 2")) {
                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-EventSubprocessSignal");
    assertProcessInstanceActive(processInstance);
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoWorkItem workItemTopProcess = workItemHandler.getWorkItem();
    kruntime.signalEvent("MySignal", null, processInstance.getStringId());
    assertProcessInstanceActive(processInstance);
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    kruntime.signalEvent("MySignal", null);
    assertProcessInstanceActive(processInstance);
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertThat(workItemTopProcess).isNotNull();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItemTopProcess.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "User Task 2", "end-sub");
    assertThat(executednodes.size()).isEqualTo(4);
}
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) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test)

Example 23 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class EscalationEventTest method testEventSubprocessEscalation.

@Test
public void testEventSubprocessEscalation() throws Exception {
    kruntime = createKogitoProcessRuntime("escalation/BPMN2-EventSubprocessEscalation.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-EventSubprocessEscalation");
    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)

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