Search in sources :

Example 6 with Application

use of io.automatiko.engine.api.Application 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 7 with Application

use of io.automatiko.engine.api.Application 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 8 with Application

use of io.automatiko.engine.api.Application 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)

Example 9 with Application

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

the class UserTaskTest method testBasicUserTaskProcessPhases.

@Test
public void testBasicUserTaskProcessPhases() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("SecondTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 10 with Application

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

the class UserTaskTest method testApprovalWithReadonlyVariableTags.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testApprovalWithReadonlyVariableTags() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval-with-readonly-variable-tags.bpmn2");
    assertThat(app).isNotNull();
    Class<?> resourceClazz = Class.forName("org.acme.travels.ApprovalsModel", true, testClassLoader());
    assertNotNull(resourceClazz);
    Field approverField = resourceClazz.getDeclaredField("approver");
    assertThat(approverField).isNotNull();
    assertThat(approverField.getType().getCanonicalName()).isEqualTo(String.class.getCanonicalName());
    Process<? extends Model> p = app.processes().processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("approver", "john");
    m.fromMap(parameters);
    ProcessInstance processInstance = p.createInstance(m);
    processInstance.start();
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.status());
    final Model updates = p.createModel();
    parameters = new HashMap<>();
    parameters.put("approver", "mary");
    updates.fromMap(parameters);
    // updating readonly variable should fail
    assertThrows(VariableViolationException.class, () -> processInstance.updateVariables(updates));
    processInstance.abort();
    assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ABORTED, processInstance.status());
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (io.automatiko.engine.api.Application)157 Model (io.automatiko.engine.api.Model)146 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)143 Test (org.junit.jupiter.api.Test)143 HashMap (java.util.HashMap)126 WorkItem (io.automatiko.engine.api.workflow.WorkItem)46 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)29 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)27 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)27 ArrayList (java.util.ArrayList)17 List (java.util.List)16 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)14 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)14 Process (io.automatiko.engine.api.workflow.Process)13 Map (java.util.Map)12 Person (io.automatiko.engine.codegen.data.Person)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)9 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)8