Search in sources :

Example 16 with DefaultProcessEventListener

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

the class ActivityTest method testCallActivityWithTransformation.

@Test
public void testCallActivityWithTransformation() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityWithTransformation.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            instances.add(event.getProcessInstance());
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, instances.size());
    // assert variables of parent process, first in start (input transformation, then on end output transformation)
    assertEquals("oldValue", ((WorkflowProcessInstance) instances.get(0)).getVariable("x"));
    assertEquals("NEW VALUE", ((WorkflowProcessInstance) instances.get(0)).getVariable("y"));
    // assert variables of subprocess, first in start (input transformation, then on end output transformation)
    assertEquals("OLDVALUE", ((WorkflowProcessInstance) instances.get(1)).getVariable("subX"));
    assertEquals("new value", ((WorkflowProcessInstance) instances.get(1)).getVariable("subY"));
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) 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 17 with DefaultProcessEventListener

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

the class ActivityTest method testSubProcessWithTerminateEndEventProcessScope.

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

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            list.add(event.getNodeInstance().getNodeName());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("SubProcessTerminate");
    assertProcessInstanceCompleted(processInstance);
    assertEquals(5, list.size());
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) 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 18 with DefaultProcessEventListener

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

the class ActivityTest method testCallActivityMI.

@Test
public void testCallActivityMI() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityMI.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<Long> subprocessStarted = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            if (event.getProcessInstance().getProcessId().equals("SubProcess")) {
                subprocessStarted.add(event.getProcessInstance().getId());
            }
        }
    });
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    params.put("list", list);
    params.put("listOut", listOut);
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, subprocessStarted.size());
    listOut = (List) ((WorkflowProcessInstance) processInstance).getVariable("listOut");
    assertNotNull(listOut);
    assertEquals(2, listOut.size());
    assertEquals("new value", listOut.get(0));
    assertEquals("new value", listOut.get(1));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 19 with DefaultProcessEventListener

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

the class ActivityTest method testMinimalProcessMetaData.

@Test
public void testMinimalProcessMetaData() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MinimalProcessMetaData.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<String> list1 = new ArrayList<String>();
    final List<String> list2 = new ArrayList<String>();
    final List<String> list3 = new ArrayList<String>();
    final List<String> list4 = new ArrayList<String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.debug("before node");
            Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTag");
            if (customTag != null) {
                list1.add(customTag);
            }
            String customTag2 = (String) metaData.get("customTag2");
            if (customTag2 != null) {
                list2.add(customTag2);
            }
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug("after variable");
            VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
            if (variableScope == null) {
                return;
            }
            Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagVar");
            if (customTag != null) {
                list3.add(customTag);
            }
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            logger.debug("after process");
            Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagProcess");
            if (customTag != null) {
                list4.add(customTag);
            }
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "krisv");
    ProcessInstance processInstance = ksession.startProcess("Minimal", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(3, list1.size());
    assertEquals(2, list2.size());
    assertEquals(1, list3.size());
    assertEquals(1, list4.size());
}
Also used : ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KieBase(org.kie.api.KieBase) 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) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Test(org.junit.Test)

Example 20 with DefaultProcessEventListener

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

the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.

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

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    ksession.signalEvent("startSignal", null);
    assertThat(list.size()).isEqualTo(1);
    WorkItem workItem = workItemHandler.getWorkItem();
    long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    ksession = restoreSession(ksession, true);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Aggregations

DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)98 Test (org.junit.Test)87 ArrayList (java.util.ArrayList)69 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)59 KieBase (org.kie.api.KieBase)57 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)48 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)48 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)40 KieSession (org.kie.api.runtime.KieSession)38 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)30 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)27 WorkItem (org.kie.api.runtime.process.WorkItem)27 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)26 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)25 HashMap (java.util.HashMap)24 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)19 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)9 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)7