Search in sources :

Example 26 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class FlowTest method testMultipleGatewaysProcess.

@Test
public void testMultipleGatewaysProcess() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultipleGatewaysProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new DefaultProcessEventListener() {

        ProcessInstance pi;

        @Override
        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("CreateAgent")) {
                pi.signalEvent("Signal_1", null);
            }
        }

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.info("Before Node triggered event received for node: {}", event.getNodeInstance().getNodeName());
        }

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            pi = event.getProcessInstance();
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("action", "CreateAgent");
    ProcessInstance processInstance = ksession.startProcess("multiplegateways", params);
    assertProcessInstanceCompleted(processInstance);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 27 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class ActivityTest method testSubProcess.

@Test
public void testSubProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            logger.debug(event.toString());
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug(event.toString());
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug(event.toString());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("SubProcess");
    assertProcessInstanceCompleted(processInstance);
}
Also used : ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) KieBase(org.kie.api.KieBase) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 28 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testMessageStart.

@Test
public void testMessageStart() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MessageStart.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    final List<Long> list = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    ksession.signalEvent("Message-HelloMessage", "NewValue");
    assertThat(list.size()).isEqualTo(1);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 29 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class StartEventTest method testMultipleEventBasedStartEventsStartOnTimer.

@Test(timeout = 10000)
public void testMultipleEventBasedStartEventsStartOnTimer() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartTimer", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<Long> list = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    assertThat(list.size()).isEqualTo(0);
    // Timer in the process takes 500ms, so after 1 second, there should be 2 process IDs in the list.
    countDownListener.waitTillCompleted();
    assertThat(getNumberOfProcessInstances("MultipleStartEvents")).isEqualTo(2);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) Test(org.junit.Test)

Example 30 with ProcessStartedEvent

use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.

the class StartEventTest method testSignalStartDynamic.

@Test
public void testSignalStartDynamic() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2");
    ksession = createKnowledgeSession(kbase);
    // create KieContainer after session was created to make sure no runtime data
    // will be used during serialization (deep clone)
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    kContainer.getKieBase();
    final List<Long> list = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void beforeProcessStarted(ProcessStartedEvent event) {
            logger.info("{}", event.getProcessInstance().getId());
            list.add(event.getProcessInstance().getId());
        }
    });
    ksession.signalEvent("MySignal", "NewValue");
    assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
    // now remove the process from kbase to make sure runtime based listeners are removed from signal manager
    kbase.removeProcess("Minimal");
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
        ksession.signalEvent("MySignal", "NewValue");
    }).withMessageContaining("Unknown process ID: Minimal");
    // must be still one as the process was removed
    assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
}
Also used : KieRepository(org.kie.api.builder.KieRepository) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieServices(org.kie.api.KieServices) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)57 Test (org.junit.Test)55 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)48 ArrayList (java.util.ArrayList)45 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)29 KieBase (org.kie.api.KieBase)29 KieSession (org.kie.api.runtime.KieSession)23 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)15 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 HashMap (java.util.HashMap)10 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)9 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)8 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)8 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)7 ProcessEvent (org.kie.api.event.process.ProcessEvent)6 WorkItem (org.kie.api.runtime.process.WorkItem)6