Search in sources :

Example 21 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class SubProcessTest method testNonExistentSubProcess.

@Test
public void testNonExistentSubProcess() {
    String nonExistentSubProcessName = "nonexistent.process";
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.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);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    ProcessInstance pi = ksession.startProcess("org.company.core.process.process");
    assertEquals(ProcessInstance.STATE_ERROR, pi.getState());
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) 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) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 22 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.

@Test
public void testMockDataWorkItemHandlerCustomFunction() {
    String processId = "org.company.actions";
    String workName = "Unnexistent Task";
    ExecutableProcess process = getWorkItemProcess(processId, workName);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    ksession.getWorkItemManager().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"));
    ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
    Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("one", numberVariable);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    parameters.put("Person", new Person("John Deen"));
    processInstance = ksession.startProcess("org.company.actions", parameters);
    numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
    assertNotNull(numberVariable);
    assertEquals("two", numberVariable);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockDataWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Node(io.automatiko.engine.workflow.process.core.Node) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Set(java.util.Set) DoNothingWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.DoNothingWorkItemHandler) Test(org.junit.jupiter.api.Test) List(java.util.List) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Person(io.automatiko.engine.workflow.process.test.Person) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) Work(io.automatiko.engine.workflow.base.core.Work) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) 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) HashMap(java.util.HashMap) Map(java.util.Map) 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 23 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance 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 24 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationBoundaryEventSpecificTest.

public static void runCompensationBoundaryEventSpecificTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // call compensation on the uncompleted work 1 (which should not fire)
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // complete work 1
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    // call compensation on work 1, which should now fire
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(1, eventList.size(), "Compensation should have fired.");
    // complete work 2 & 3
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 25 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationEventSubProcessGeneralTest.

public static void runCompensationEventSubProcessGeneralTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // pre and sub process work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    // Call general compensation
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(1, eventList.size(), "Compensation should have fired once.");
    // post work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)56 ArrayList (java.util.ArrayList)25 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)19 List (java.util.List)18 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)17 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)16 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)16 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)16 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)16 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)16 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)16 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)16 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)15 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)15 ProcessSignaledEvent (io.automatiko.engine.api.event.process.ProcessSignaledEvent)15 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)15 SLAViolatedEvent (io.automatiko.engine.api.event.process.SLAViolatedEvent)15 UnitOfWorkManager (io.automatiko.engine.api.uow.UnitOfWorkManager)15 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)15 Transition (io.automatiko.engine.api.workflow.workitem.Transition)15