Search in sources :

Example 1 with KogitoProcessInstance

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

the class SubProcessTest method testNonExistentSubProcess.

@Test
public void testNonExistentSubProcess() {
    String nonExistentSubProcessName = "nonexistent.process";
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(2);
    subProcessNode.setProcessId(nonExistentSubProcessName);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, subProcessNode);
    connect(subProcessNode, endNode);
    process.addNode(startNode);
    process.addNode(subProcessNode);
    process.addNode(endNode);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
    KogitoProcessInstance pi = kruntime.startProcess("org.drools.core.process.process");
    assertEquals(KogitoProcessInstance.STATE_ERROR, pi.getState());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) EndNode(org.jbpm.workflow.core.node.EndNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with KogitoProcessInstance

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

the class WorkItemTest method testReachNonRegisteredWorkItemHandler.

@Test
public void testReachNonRegisteredWorkItemHandler() {
    String processId = "org.drools.actions";
    String workName = "Unnexistent Task";
    RuleFlowProcess process = getWorkItemProcess(processId, workName);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Doe"));
    KogitoProcessInstance processInstance = null;
    try {
        processInstance = kruntime.startProcess("org.drools.actions", parameters);
        fail("should fail if WorkItemHandler for" + workName + "is not registered");
    } catch (Throwable e) {
    }
    assertEquals(KogitoProcessInstance.STATE_ERROR, processInstance.getState());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Person(org.jbpm.process.test.Person) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with KogitoProcessInstance

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

the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.

@Test
public void testMockDataWorkItemHandlerCustomFunction() {
    String processId = "org.drools.actions";
    String workName = "Unnexistent Task";
    RuleFlowProcess process = getWorkItemProcess(processId, workName);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler((input) -> {
        Map<String, Object> output = new HashMap<String, Object>();
        if ("John Doe".equals(input.get("Comment"))) {
            output.put("Result", "one");
        } else {
            output.put("Result", "two");
        }
        return output;
    }));
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Doe"));
    KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.actions", parameters);
    Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("one", numberVariable);
    assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
    parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Deen"));
    processInstance = kruntime.startProcess("org.drools.actions", parameters);
    numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("two", numberVariable);
    assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) LoggerFactory(org.slf4j.LoggerFactory) StartNode(org.jbpm.workflow.core.node.StartNode) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockDataWorkItemHandler(org.jbpm.process.instance.impl.demo.MockDataWorkItemHandler) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Variable(org.jbpm.process.core.context.variable.Variable) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) EndNode(org.jbpm.workflow.core.node.EndNode) Person(org.jbpm.process.test.Person) Set(java.util.Set) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) KogitoWorkItemHandlerNotFoundException(org.kie.kogito.process.workitems.KogitoWorkItemHandlerNotFoundException) Test(org.junit.jupiter.api.Test) List(java.util.List) Node(org.jbpm.workflow.core.Node) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) ParameterDefinitionImpl(org.jbpm.process.core.impl.ParameterDefinitionImpl) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) MockDataWorkItemHandler(org.jbpm.process.instance.impl.demo.MockDataWorkItemHandler) HashMap(java.util.HashMap) Map(java.util.Map) Person(org.jbpm.process.test.Person) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with KogitoProcessInstance

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

the class NodeInnerClassesTest method testNodeReading.

@Test
public void testNodeReading() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.event");
    process.setName("Event Process");
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType();
    personDataType.setClassName("org.drools.Person");
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    process.setDynamic(true);
    CompositeNode compositeNode = new CompositeNode();
    compositeNode.setName("CompositeNode");
    compositeNode.setId(2);
    ForEachNode forEachNode = new ForEachNode();
    ForEachNode.ForEachSplitNode split = new ForEachNode.ForEachSplitNode();
    split.setName("ForEachSplit");
    split.setMetaData("hidden", true);
    split.setMetaData("UniqueId", forEachNode.getMetaData("Uniqueid") + ":foreach:split");
    forEachNode.internalAddNode(split);
    forEachNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, new CompositeNode.NodeAndType(split, Node.CONNECTION_DEFAULT_TYPE));
    process.addNode(forEachNode);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    kruntime.getProcessEventManager().addEventListener(procEventListener);
    KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.process.event");
    assertNotNull(processInstance);
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Variable(org.jbpm.process.core.context.variable.Variable) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) ArrayList(java.util.ArrayList) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with KogitoProcessInstance

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

the class ProcessEventSupportTest method testProcessEventListenerWithEvent.

@Test
public void testProcessEventListenerWithEvent() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.event");
    process.setName("Event Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", (Action) context -> logger.info("Executed action"));
    actionNode.setAction(action);
    actionNode.setId(2);
    process.addNode(actionNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EventNode eventNode = new EventNode();
    eventNode.setName("Event");
    eventNode.setId(3);
    List<EventFilter> filters = new ArrayList<EventFilter>();
    EventTypeFilter filter = new EventTypeFilter();
    filter.setType("signal");
    filters.add(filter);
    eventNode.setEventFilters(filters);
    process.addNode(eventNode);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, eventNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(4);
    process.addNode(endNode);
    new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
    final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }
    };
    kruntime.getProcessEventManager().addEventListener(processEventListener);
    // execute the process
    KogitoProcessInstance pi = kruntime.startProcess("org.drools.core.process.event");
    pi.signalEvent("signal", null);
    assertEquals(20, processEventList.size());
    assertEquals("org.drools.core.process.event", processEventList.get(0).getProcessInstance().getProcessId());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(6)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(7)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(8)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
    assertEquals("org.drools.core.process.event", processEventList.get(11).getProcessInstance().getProcessId());
    assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(12)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(13)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(14)).getNodeInstance().getNodeName());
    assertEquals("org.drools.core.process.event", processEventList.get(15).getProcessInstance().getProcessId());
    assertEquals("org.drools.core.process.event", processEventList.get(16).getProcessInstance().getProcessId());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(17)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(19)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(18)).getNodeInstance().getNodeName());
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) EventFilter(org.jbpm.process.core.event.EventFilter) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) LoggerFactory(org.slf4j.LoggerFactory) StartNode(org.jbpm.workflow.core.node.StartNode) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) DroolsAction(org.jbpm.workflow.core.DroolsAction) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Node(org.jbpm.workflow.core.Node) Action(org.jbpm.process.instance.impl.Action) ProcessEvent(org.kie.api.event.process.ProcessEvent) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ProcessEvent(org.kie.api.event.process.ProcessEvent) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) ActionNode(org.jbpm.workflow.core.node.ActionNode) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventFilter(org.jbpm.process.core.event.EventFilter) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EndNode(org.jbpm.workflow.core.node.EndNode) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)493 Test (org.junit.jupiter.api.Test)450 HashMap (java.util.HashMap)209 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)143 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)130 ArrayList (java.util.ArrayList)126 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)83 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)71 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)70 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)62 StringReader (java.io.StringReader)58 Disabled (org.junit.jupiter.api.Disabled)58 Reader (java.io.Reader)52 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)51 NodeLeftCountDownProcessEventListener (org.jbpm.test.util.NodeLeftCountDownProcessEventListener)49 Timeout (org.junit.jupiter.api.Timeout)48 ReaderResource (org.drools.core.io.impl.ReaderResource)46 Map (java.util.Map)39 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)39 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)35