Search in sources :

Example 6 with Model

use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testParallelExecWorkflow.

@Test
public void testParallelExecWorkflow() throws Exception {
    Application app = generateCodeProcessesOnly("serverless/parallel-state.sw.json", "serverless/parallel-state-branch1.sw.json", "serverless/parallel-state-branch2.sw.json");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("parallelworkflow_1_0");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("branch1data", "branch2data");
    Map<String, Object> dataOut = result.toMap();
    assertThat(((JsonNode) dataOut.get("branch1data")).textValue()).isEqualTo("testBranch1Data");
    assertThat(((JsonNode) dataOut.get("branch2data")).textValue()).isEqualTo("testBranch2Data");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Model

use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testCompensationWorkflow.

@Disabled
@ParameterizedTest
@ValueSource(strings = { "serverless/compensation.sw.json" })
public void testCompensationWorkflow(String processLocation) throws Exception {
    Application app = generateCodeProcessesOnly(processLocation);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("compensationworkflow");
    Model m = p.createModel();
    String jsonParamStr = "{\"x\": \"0\"}";
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonParamObj = mapper.readTree(jsonParamStr);
    m.fromMap(toMap(jsonParamObj));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("x");
    JsonNode dataOut = (JsonNode) result.toMap().get("x");
    assertThat(dataOut.textValue()).isEqualTo("2");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Disabled(org.junit.jupiter.api.Disabled)

Example 8 with Model

use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testSingleInjectWithExecTimeoutWorkflow.

@ParameterizedTest
@ValueSource(strings = { "serverless/single-inject-state-timeout.sw.json" })
public void testSingleInjectWithExecTimeoutWorkflow(String processLocation) throws Exception {
    Application app = generateCodeProcessesOnly(processLocation);
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Execution timeout :: end", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("singleinject_1_0");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("name");
    JsonNode dataOut = (JsonNode) result.toMap().get("name");
    assertThat(dataOut.textValue()).isEqualTo("john");
    boolean completed = listener.waitTillCompleted(3000000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("name");
    dataOut = (JsonNode) result.toMap().get("name");
    assertThat(dataOut.textValue()).isEqualTo("anothernotset");
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Model

use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testParallelExecWorkflowNumCompleted.

@Disabled
@Test
public void testParallelExecWorkflowNumCompleted() throws Exception {
    Application app = generateCodeProcessesOnly("serverless/parallel-state-num-completed.sw.json", "serverless/parallel-state-branch1.sw.json", "serverless/parallel-state-branch2.sw.json");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("parallelworkflow_1_0");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("branch2data");
    Map<String, Object> dataOut = result.toMap();
    assertThat(((JsonNode) dataOut.get("branch2data")).textValue()).isEqualTo("testBranch2Data");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Disabled(org.junit.jupiter.api.Disabled)

Example 10 with Model

use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testLogVarWorkflow.

@ParameterizedTest
@ValueSource(strings = { "serverless/logvar.sw.json" })
public void testLogVarWorkflow(String processLocation) throws Exception {
    Application app = generateCodeProcessesOnly(processLocation);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("logvar_1_0");
    Model m = p.createModel();
    String jsonParamStr = "{\"name\": \"john\"}";
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonParamObj = mapper.readTree(jsonParamStr);
    m.fromMap(toMap(jsonParamObj));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("name");
    JsonNode dataOut = (JsonNode) result.toMap().get("name");
    assertThat(dataOut.textValue()).isEqualTo("john");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Model (io.automatiko.engine.api.Model)161 Application (io.automatiko.engine.api.Application)142 Test (org.junit.jupiter.api.Test)138 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)133 HashMap (java.util.HashMap)127 WorkItem (io.automatiko.engine.api.workflow.WorkItem)43 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)26 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)23 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)23 ArrayList (java.util.ArrayList)16 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Person (io.automatiko.engine.codegen.data.Person)10 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)10 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)9 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 List (java.util.List)9 DataEvent (io.automatiko.engine.api.event.DataEvent)8 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)8