Search in sources :

Example 16 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class WorkItemTest method testMockDataWorkItemHandler.

@Test
public void testMockDataWorkItemHandler() {
    String processId = "org.company.actions";
    String workName = "Unnexistent Task";
    ExecutableProcess process = getWorkItemProcess(processId, workName);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("Result", "test");
    ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler(output));
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Doe"));
    ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
    Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("test", numberVariable);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : HashMap(java.util.HashMap) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) MockDataWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler) Person(io.automatiko.engine.workflow.process.test.Person) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 17 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class WorkItemTest method getWorkItemProcess.

private ExecutableProcess getWorkItemProcess(String processId, String workName) {
    ExecutableProcess process = new ExecutableProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("UserName");
    variable.setType(new StringDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Person");
    variable.setType(new ObjectDataType(Person.class));
    variables.add(variable);
    variable = new Variable();
    variable.setName("MyObject");
    variable.setType(new ObjectDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Number");
    variable.setType(new IntegerDataType());
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    workItemNode.addInMapping("Comment", "Person.name");
    workItemNode.addInMapping("Attachment", "MyObject");
    workItemNode.addOutMapping("Result", "MyObject");
    workItemNode.addOutMapping("Result.length()", "Number");
    Work work = new WorkImpl();
    work.setName(workName);
    Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Content", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("ActorId", "#{UserName}");
    work.setParameter("Content", "#{Person.name}");
    workItemNode.setWork(work);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, workItemNode);
    connect(workItemNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(endNode);
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Person(io.automatiko.engine.workflow.process.test.Person) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) HashSet(java.util.HashSet)

Example 18 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class CompensationTest method testNestedCompensationBoundaryEventGeneral.

@Test
public void testNestedCompensationBoundaryEventGeneral() throws Exception {
    String processId = "org.jbpm.process.compensation.boundary.general.nested";
    String[] workItemNames = { "Jip", "Janneke", "Takkie" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createNestedCompensationBoundaryEventProcess(processId, workItemNames, eventList);
    // run process
    ksession = createProcessRuntime(process);
    Node toCompensateNode = findNode(process, "sub2");
    String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + (String) toCompensateNode.getMetaData().get("UniqueId");
    runCompensationBoundaryEventGeneralTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 19 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class CompensationTest method testCompensationEventSubProcessGeneral.

@Test
public void testCompensationEventSubProcessGeneral() throws Exception {
    String processId = "org.jbpm.process.compensation.event.subprocess.general";
    String[] workItemNames = { "kwik", "kwek", "kwak" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createCompensationEventSubProcessProcess(processId, workItemNames, eventList);
    String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + process.getId();
    // run process
    ksession = createProcessRuntime(process);
    runCompensationEventSubProcessGeneralTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
Also used : ArrayList(java.util.ArrayList) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 20 with ExecutableProcess

use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.

the class CompensationTest method createNestedCompensationEventSubProcessProcess.

private ExecutableProcess createNestedCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    // outer process
    CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
    {
        StartNode startNode = startNodeCreator.createNode("start0");
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
        workItemNode.getWork().setName(workItemNames[0]);
        connect(startNode, workItemNode);
        connect(workItemNode, compositeNode);
        EndNode endNode = endNodeCreator.createNode("end0");
        connect(compositeNode, endNode);
    }
    // 1rst level nested subprocess (contains compensation visibility scope)
    CompositeContextNode compensationScopeContainerNode = compositeNode;
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start1");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
        connect(startNode, subCompNode);
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work1-post");
        workItemNode.getWork().setName(workItemNames[2]);
        connect(subCompNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end1");
        connect(workItemNode, endNode);
        compositeNode = subCompNode;
    }
    // 2nd level nested subprocess
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start2");
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
        workItemNode.getWork().setName(workItemNames[1]);
        connect(startNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end2");
        connect(workItemNode, endNode);
    }
    // 3nd level nested event subprocess in 2nd level subprocess
    {
        NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
        EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
        startNodeCreator.setNodeContainer(espNode);
        endNodeCreator.setNodeContainer(espNode);
        NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
        EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
        eventFilter.setType("Compensation");
        espNode.addEvent(eventFilter);
        addCompensationScope(espNode, compensationScopeContainerNode, (String) compositeNode.getMetaData("UniqueId"));
        StartNode startNode = startNodeCreator.createNode("start3*");
        ActionNode actionNode = actionNodeCreator.createNode("action3*");
        actionNode.setName("Execute");
        ProcessAction action = new ConsequenceAction("java", null);
        action.setMetaData("Action", new Action() {

            public void execute(ProcessContext context) throws Exception {
                eventList.add("Executed action");
            }
        });
        actionNode.setAction(action);
        connect(startNode, actionNode);
        EndNode endNode = endNodeCreator.createNode("end3*");
        connect(actionNode, endNode);
    }
    return process;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Aggregations

ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)58 ArrayList (java.util.ArrayList)29 Test (org.junit.jupiter.api.Test)29 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)28 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)26 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)23 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)20 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)16 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)16 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)15 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)14 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)13 Node (io.automatiko.engine.workflow.process.core.Node)12 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)12 List (java.util.List)12 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)11 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)11 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)10 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)10 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)9