Search in sources :

Example 56 with DefaultProcessEventListener

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

the class FlowTest method testMultiInstanceLoopNumberTest.

@Test
public void testMultiInstanceLoopNumberTest() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoop-Numbering.bpmn2");
    ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    final Map<String, String> nodeIdNodeNameMap = new HashMap<String, String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            NodeInstance nodeInstance = event.getNodeInstance();
            String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId();
            String nodeName = ((NodeInstanceImpl) nodeInstance).getNode().getName();
            String prevNodeName = nodeIdNodeNameMap.put(uniqId, nodeName);
            if (prevNodeName != null) {
                assertEquals(uniqId + " is used for more than one node instance: ", prevNodeName, nodeName);
            }
        }
    });
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("Test.MultipleInstancesBug", params);
    List<WorkItem> workItems = handler.getWorkItems();
    logger.debug("COMPLETING TASKS.");
    ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItems.remove(0).getId(), null);
    assertProcessInstanceCompleted(processInstance);
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) 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) NodeInstance(org.kie.api.runtime.process.NodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) ForEachJoinNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) Test(org.junit.Test)

Example 57 with DefaultProcessEventListener

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

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

the class FlowTest method testInclusiveSplitWithLoopInsideSubprocess.

@Test
public void testInclusiveSplitWithLoopInsideSubprocess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInsideSubprocess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
            Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
            if (value == null) {
                value = new Integer(0);
            }
            value++;
            nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
        }
    });
    TestWorkItemHandler handler = new TestWorkItemHandler();
    TestWorkItemHandler handler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", -1);
    ProcessInstance processInstance = ksession.startProcess("Process_1", params);
    assertProcessInstanceActive(processInstance);
    List<WorkItem> workItems = handler.getWorkItems();
    assertNotNull(workItems);
    assertEquals(2, workItems.size());
    for (WorkItem wi : workItems) {
        assertProcessInstanceActive(processInstance);
        ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    }
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(13, nodeInstanceExecutionCounter.size());
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Sub Process 1"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-end"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
    assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) 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) Test(org.junit.Test)

Example 59 with DefaultProcessEventListener

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

the class FlowTest method testInclusiveSplitWithLoopInside.

@Test
public void testInclusiveSplitWithLoopInside() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInside.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
            Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
            if (value == null) {
                value = new Integer(0);
            }
            value++;
            nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
        }
    });
    TestWorkItemHandler handler = new TestWorkItemHandler();
    TestWorkItemHandler handler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", -1);
    ProcessInstance processInstance = ksession.startProcess("Process_1", params);
    assertProcessInstanceActive(processInstance);
    List<WorkItem> workItems = handler.getWorkItems();
    assertNotNull(workItems);
    assertEquals(2, workItems.size());
    for (WorkItem wi : workItems) {
        assertProcessInstanceActive(processInstance);
        ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    }
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(10, nodeInstanceExecutionCounter.size());
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
    assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) 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) Test(org.junit.Test)

Example 60 with DefaultProcessEventListener

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

the class ActivityTest method testSubProcessWithTypeVariable.

@Test
public void testSubProcessWithTypeVariable() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/BPMN2-SubProcessWithTypeVariable.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<String> list = new ArrayList<String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Read Map")) {
                list.add(event.getNodeInstance().getNodeName());
            }
        }
    });
    ProcessInstance processInstance = ksession.startProcess("sub_variable.sub_variables");
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, 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)

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