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");
}
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");
}
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");
}
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);
}
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());
}
Aggregations