Search in sources :

Example 36 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class DataTest method testDataInputAssociationsWithStringWithoutQuotes.

@Test
public void testDataInputAssociationsWithStringWithoutQuotes() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-string-no-quotes.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    ProcessInstance processInstance = ksession.startProcess("process", null);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 37 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class DataTest method testDataInputAssociationsWithLazyLoading.

/**
 * TODO testDataInputAssociationsWithLazyLoading
 */
@Test
@Ignore
public void testDataInputAssociationsWithLazyLoading() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-lazy-creating.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {

        public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
        }

        public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
            Object coIdParamObj = workItem.getParameter("coId");
            assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
            assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
            assertEquals("user", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getNodeName());
            assertEquals("hello world", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
        }
    });
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("instanceMetadata", document.getFirstChild());
    ProcessInstance processInstance = ksession.startProcess("process", params);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Element(org.w3c.dom.Element) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Document(org.w3c.dom.Document) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.

@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            if (workItem.getParameter("ActorId").equals("mary")) {
                throw new MyError();
            }
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
    assertProcessInstanceActive(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 39 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class ErrorEventTest method testErrorBoundaryEventOnExit.

@Test
public void testErrorBoundaryEventOnExit() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnExitException.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnExit");
    assertProcessInstanceActive(processInstance.getId(), ksession);
    WorkItem workItem = handler.getWorkItem();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertEquals(1, handler.getWorkItems().size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 40 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class FlowTest method testInclusiveParallelExclusiveSplitNoLoop.

@Test
public void testInclusiveParallelExclusiveSplitNoLoop() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-InclusiveNestedInParallelNestedInExclusive.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("testWI", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("testWI2", new SystemOutWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            Integer x = (Integer) workItem.getParameter("input1");
            x++;
            Map<String, Object> results = new HashMap<String, Object>();
            results.put("output1", x);
            manager.completeWorkItem(workItem.getId(), results);
        }
    });
    final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.info(event.getNodeInstance().getNodeName());
            Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
            if (value == null) {
                value = new Integer(0);
            }
            value++;
            nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", 0);
    ProcessInstance processInstance = ksession.startProcess("Process_1", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(12, nodeInstanceExecutionCounter.size());
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("ANDGateway-diverging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("ORGateway-diverging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI3"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI2"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("ORGateway-converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("Script"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-diverging"));
    assertEquals(2, (int) nodeInstanceExecutionCounter.get("ANDGateway-converging"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI6"));
    assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
Also used : HashMap(java.util.HashMap) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) 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) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

WorkItem (org.kie.api.runtime.process.WorkItem)174 Test (org.junit.Test)139 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)127 KieBase (org.kie.api.KieBase)110 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)91 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)87 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)48 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)33 ArrayList (java.util.ArrayList)29 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)26 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)22 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)14 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 Map (java.util.Map)11 StringReader (java.io.StringReader)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)10