Search in sources :

Example 21 with ExecutableProcess

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

the class CompensationTest method createCompensationBoundaryEventProcess.

private ExecutableProcess createCompensationBoundaryEventProcess(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);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(process, BoundaryEventNode.class);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(process, ActionNode.class);
    // Create process
    StartNode startNode = startNodeCreator.createNode("start");
    Node lastNode = startNode;
    WorkItemNode[] workItemNodes = new WorkItemNode[3];
    for (int i = 0; i < 3; ++i) {
        workItemNodes[i] = workItemNodeCreator.createNode("work" + (i + 1));
        workItemNodes[i].getWork().setName(workItemNames[i]);
        connect(lastNode, workItemNodes[i]);
        lastNode = workItemNodes[i];
    }
    EndNode endNode = endNodeCreator.createNode("end");
    connect(workItemNodes[2], endNode);
    // Compensation (boundary event) handlers
    for (int i = 0; i < 3; ++i) {
        createBoundaryEventCompensationHandler(process, workItemNodes[i], eventList, "" + i + 1);
    }
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) 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) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) 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)

Example 22 with ExecutableProcess

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

the class CompensationTest method testCompensationBoundaryEventSpecific.

/*
	 * TESTS
	 */
@Test
public void testCompensationBoundaryEventSpecific() throws Exception {
    String processId = "org.jbpm.process.compensation.boundary";
    String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createCompensationBoundaryEventProcess(processId, workItemNames, eventList);
    // run process
    ksession = createProcessRuntime(process);
    Node compensatedNode = findNode(process, "work1");
    String compensationEvent = (String) compensatedNode.getMetaData().get("UniqueId");
    runCompensationBoundaryEventSpecificTest(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 23 with ExecutableProcess

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

the class CompensationTest method testNestedCompensationEventSubProcessGeneral.

@Test
public void testNestedCompensationEventSubProcessGeneral() throws Exception {
    String processId = "org.jbpm.process.compensation.event.subprocess.general";
    String[] workItemNames = { "apple", "banana", "orange" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createNestedCompensationEventSubProcessProcess(processId, workItemNames, eventList);
    Node toCompensateNode = findNode(process, "sub0");
    String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + toCompensateNode.getMetaData().get("UniqueId");
    ksession = createProcessRuntime(process);
    runCompensationEventSubProcessGeneralTest(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 24 with ExecutableProcess

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

the class CompensationTest method testNestedCompensationBoundaryEventSpecific.

@Test
public void testNestedCompensationBoundaryEventSpecific() throws Exception {
    String processId = "org.jbpm.process.compensation.boundary.nested";
    String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
    List<String> eventList = new ArrayList<String>();
    ExecutableProcess process = createNestedCompensationBoundaryEventProcess(processId, workItemNames, eventList);
    // run process
    ksession = createProcessRuntime(process);
    Node compensatedNode = findNode(process, "work-comp-1");
    String compensationEvent = (String) compensatedNode.getMetaData().get("UniqueId");
    runCompensationBoundaryEventSpecificTest(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 25 with ExecutableProcess

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

the class ProcessEventSupportTest method testProcessEventListener.

@Test
public void testProcessEventListener() throws Exception {
    // create a simple package with one process to test the events
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.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");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            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);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    process.addNode(endNode);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), 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);
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    processRuntime.startProcess("org.company.core.process.event");
    assertEquals(16, processEventList.size());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) 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("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(7)).getProcessInstance().getProcessId());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(8)).getProcessInstance().getProcessId());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(13)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(14)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) 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) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) ArrayList(java.util.ArrayList) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

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