Search in sources :

Example 56 with ProcessStartedEvent

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

the class PerRequestRuntimeManagerTest method testEventSignalingBetweenProcesses.

@Test
public void testEventSignalingBetweenProcesses() {
    final Map<String, Integer> processStates = new HashMap<String, Integer>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void afterProcessCompleted(ProcessCompletedEvent event) {
                    processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
                }

                @Override
                public void beforeProcessStarted(ProcessStartedEvent event) {
                    processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ksession.startProcess("com.sample.bpmn.hello");
    assertEquals(2, processStates.size());
    assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
    assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
    assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
    assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 57 with ProcessStartedEvent

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

the class SingletonRuntimeManagerTest method testEventSignalingBetweenProcesses.

@Test
public void testEventSignalingBetweenProcesses() {
    final Map<String, Integer> processStates = new HashMap<String, Integer>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void afterProcessCompleted(ProcessCompletedEvent event) {
                    processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
                }

                @Override
                public void beforeProcessStarted(ProcessStartedEvent event) {
                    processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ksession.startProcess("com.sample.bpmn.hello");
    assertEquals(2, processStates.size());
    assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
    assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
    assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
    assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

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