Search in sources :

Example 11 with ProcessCompletedEvent

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

the class PerProcessInstanceRuntimeManagerTest 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().newPerProcessInstanceRuntimeManager(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) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 12 with ProcessCompletedEvent

use of org.kie.api.event.process.ProcessCompletedEvent 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 13 with ProcessCompletedEvent

use of org.kie.api.event.process.ProcessCompletedEvent 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

ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)13 Test (org.junit.Test)9 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)9 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)9 ArrayList (java.util.ArrayList)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)8 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)7 KieSession (org.kie.api.runtime.KieSession)7 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)6 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)6 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)6 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)5 ProcessEvent (org.kie.api.event.process.ProcessEvent)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)4 Action (org.jbpm.process.instance.impl.Action)4 FirstErrorWorkItemHandler (org.jbpm.test.wih.FirstErrorWorkItemHandler)4 DroolsAction (org.jbpm.workflow.core.DroolsAction)4 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)4