use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {
@Override
public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("BEFORE:: " + event);
}
@Override
public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("AFTER:: " + event);
}
});
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());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(workItemTransitionEvents).hasSize(8);
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class UserTaskTest method testApprovalWithRequiredVariableTags.
@Test
public void testApprovalWithRequiredVariableTags() throws Exception {
Application app = generateCodeProcessesOnly("usertask/approval-with-required-variable-tags.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("approvals");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
assertThrows(VariableViolationException.class, () -> {
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
});
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class VariableTest method testVariablesWithReservedNameOnServiceTask.
@Test
public void testVariablesWithReservedNameOnServiceTask() throws Exception {
Application app = generateCodeProcessesOnly("servicetask/ServiceTaskWithReservedNameVariable.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("test_1_0");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("package", "john");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("result");
assertThat(result.toMap()).hasSize(2).containsKeys("package");
assertThat(result.toMap().get("result")).isNotNull().isEqualTo("Hello Hello john!!");
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class MessageStartEventTest method testMessageStartAndEndEventProcess.
@Test
public void testMessageStartAndEndEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("messagestartevent/MessageStartAndEndEvent.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("MessageStartEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start("customers", null, "CUS-00998877");
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKeys("customerId");
assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
}
use of io.automatiko.engine.api.Model in project automatiko-engine by automatiko-io.
the class MessageStartEventTest method testMultipleMessagesStartEventProcess.
@Test
public void testMultipleMessagesStartEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("messagestartevent/MessageAndMessageStartEvent.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("MessageStartEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start("customers", null, "CUS-00998877");
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("customerId");
assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
processInstance.send(Sig.of("managers", "John the manager"));
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(2, workItems.size());
result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("customerId", "path");
assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
assertThat(result.toMap().get("path")).isNotNull().isEqualTo("John the manager");
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Aggregations