Search in sources :

Example 1 with MockDataWorkItemHandler

use of io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler 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 2 with MockDataWorkItemHandler

use of io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler 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)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)2 MockDataWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.demo.MockDataWorkItemHandler)2 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)2 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)2 Person (io.automatiko.engine.workflow.process.test.Person)2 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 ParameterDefinition (io.automatiko.engine.workflow.base.core.ParameterDefinition)1 Work (io.automatiko.engine.workflow.base.core.Work)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)1 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)1 StringDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType)1 ParameterDefinitionImpl (io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl)1 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)1 DoNothingWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.demo.DoNothingWorkItemHandler)1 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)1 Node (io.automatiko.engine.workflow.process.core.Node)1