Search in sources :

Example 1 with KogitoWorkItem

use of org.kie.kogito.internal.process.runtime.KogitoWorkItem in project kogito-runtimes by kiegroup.

the class ActivityTest method testServiceTaskNoInterfaceName.

@Test
public void testServiceTaskNoInterfaceName() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler() {

        @Override
        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
            assertEquals("SimpleService", workItem.getParameter("Interface"));
            assertEquals("hello", workItem.getParameter("Operation"));
            assertEquals("java.lang.String", workItem.getParameter("ParameterType"));
            assertEquals("##WebService", workItem.getParameter("implementation"));
            assertEquals("hello", workItem.getParameter("operationImplementationRef"));
            assertEquals("SimpleService", workItem.getParameter("interfaceImplementationRef"));
            super.executeWorkItem(workItem, manager);
        }
    });
    Map<String, Object> params = new HashMap<>();
    KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("org.jboss.qa.jbpm.CallWS", params);
    assertProcessInstanceFinished(processInstance, kruntime);
}
Also used : KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) HashMap(java.util.HashMap) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 2 with KogitoWorkItem

use of org.kie.kogito.internal.process.runtime.KogitoWorkItem in project kogito-runtimes by kiegroup.

the class CompensationTest method orderedCompensation.

@Test
public void orderedCompensation() throws Exception {
    kruntime = createKogitoProcessRuntime("compensation/BPMN2-Compensation-ParallelOrderedCompensation-IntermediateThrowEvent.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<>();
    params.put("x", "");
    KogitoProcessInstance processInstance = kruntime.startProcess("CompensateParallelOrdered", params);
    List<KogitoWorkItem> workItems = workItemHandler.getWorkItems();
    List<String> workItemIds = new ArrayList<>();
    for (KogitoWorkItem workItem : workItems) {
        if ("Thr".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getStringId());
        }
    }
    for (KogitoWorkItem workItem : workItems) {
        if ("Two".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getStringId());
        }
    }
    for (KogitoWorkItem workItem : workItems) {
        if ("One".equals(workItem.getParameter("NodeName"))) {
            workItemIds.add(workItem.getStringId());
        }
    }
    for (String id : workItemIds) {
        kruntime.getKogitoWorkItemManager().completeWorkItem(id, null);
    }
    // user task -> script task (associated with compensation) --> intermeidate throw compensation event
    String xVal = getProcessVarValue(processInstance, "x");
    // Compensation happens in the *REVERSE* order of completion
    // Ex: if the order is 3, 17, 282, then compensation should happen in the order of 282, 17, 3
    // Compensation did not fire in the same order as the associated activities completed.
    Assertions.assertThat(xVal).isEqualTo("_171:_131:_141:_151:");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with KogitoWorkItem

use of org.kie.kogito.internal.process.runtime.KogitoWorkItem in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithStringObject.

@Test
public void testDataInputAssociationsWithStringObject() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-string-object.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        @Override
        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        @Override
        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    Map<String, Object> params = new HashMap<>();
    params.put("instanceMetadata", "hello");
    KogitoProcessInstance processInstance = kruntime.startProcess("process", params);
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 4 with KogitoWorkItem

use of org.kie.kogito.internal.process.runtime.KogitoWorkItem in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithStringWithoutQuotes.

@Test
public void testDataInputAssociationsWithStringWithoutQuotes() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-string-no-quotes.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
            assertEquals("hello", workItem.getParameter("coId"));
        }
    });
    KogitoProcessInstance processInstance = kruntime.startProcess("process");
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Test(org.junit.jupiter.api.Test)

Example 5 with KogitoWorkItem

use of org.kie.kogito.internal.process.runtime.KogitoWorkItem in project kogito-runtimes by kiegroup.

the class DataTest method testDataInputAssociationsWithLazyLoading.

/**
 * TODO testDataInputAssociationsWithLazyLoading
 */
@Test
@Disabled
public void testDataInputAssociationsWithLazyLoading() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-DataInputAssociations-lazy-creating.bpmn2");
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new KogitoWorkItemHandler() {

        public void abortWorkItem(KogitoWorkItem manager, KogitoWorkItemManager mgr) {
        }

        public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager 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<>();
    params.put("instanceMetadata", document.getFirstChild());
    KogitoProcessInstance processInstance = kruntime.startProcess("process", params);
}
Also used : KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Element(org.w3c.dom.Element) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)114 Test (org.junit.jupiter.api.Test)103 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)100 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)78 HashMap (java.util.HashMap)62 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)28 ArrayList (java.util.ArrayList)25 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)24 KogitoWorkItemManager (org.kie.kogito.internal.process.runtime.KogitoWorkItemManager)22 Disabled (org.junit.jupiter.api.Disabled)15 KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)15 KogitoWorkItemHandler (org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler)14 Map (java.util.Map)13 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)10 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)9 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)9 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)9 Reader (java.io.Reader)8 StringReader (java.io.StringReader)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)8