Search in sources :

Example 16 with ProcessNodeTriggeredEvent

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

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

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

Example 19 with ProcessNodeTriggeredEvent

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

the class ActivityTest method testSubProcessWithTerminateEndEvent.

@Test
public void testSubProcessWithTerminateEndEvent() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SubProcessWithTerminateEndEvent.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(7, 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 20 with ProcessNodeTriggeredEvent

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

the class DynamicProcessTest method testDynamicProcess.

@Test
public void testDynamicProcess() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
    factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
    final RuleFlowProcess process = factory.validate().getProcess();
    Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
    // source path or target path must be set to be added into kbase
    resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(resource);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(new ProcessEventListener() {

        public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
        }

        public void beforeProcessStarted(ProcessStartedEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
            logger.info("{}", arg0);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
        }

        public void afterProcessStarted(ProcessStartedEvent arg0) {
        }

        public void afterProcessCompleted(ProcessCompletedEvent arg0) {
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
        }

        public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
        }
    });
    final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
    HumanTaskNode node = new HumanTaskNode();
    node.setName("Task2");
    node.setId(4);
    insertNodeInBetween(process, 2, 3, node);
    ((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {

        public Void execute(Context context) {
            StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
            ((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
            return null;
        }
    });
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) Resource(org.kie.api.io.Resource) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) KieBase(org.kie.api.KieBase) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Test(org.junit.Test)

Aggregations

ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)24 Test (org.junit.Test)22 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)18 KieBase (org.kie.api.KieBase)14 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)9 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)8 KieSession (org.kie.api.runtime.KieSession)8 WorkItem (org.kie.api.runtime.process.WorkItem)8 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)7 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)6 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)6 Map (java.util.Map)5 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5