use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AdHocFragmentsTest method testAdHocFragments.
@Test
void testAdHocFragments() throws Exception {
Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.AdHocFragments_1_0");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
Collection<AdHocFragment> adHocFragments = processInstance.adHocFragments();
List<AdHocFragment> expected = new ArrayList<>();
expected.add(new AdHocFragment.Builder(MilestoneNode.class).withName("AdHoc Milestone").withAutoStart(true).build());
expected.add(new AdHocFragment.Builder(ActionNode.class).withName("AdHoc Script").withAutoStart(false).build());
expected.add(new AdHocFragment.Builder(HumanTaskNode.class).withName("AdHoc User Task").withAutoStart(false).build());
expected.add(new AdHocFragment.Builder(WorkItemNode.class).withName("Service Task").withAutoStart(false).build());
assertAdHocFragments(expected, adHocFragments);
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AdHocFragmentsTest method testProcessAutoStart.
@Test
void testProcessAutoStart() throws Exception {
Application app = generateCodeProcessesOnly("cases/AdHocProcess.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("AdHocProcess_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("var1", "Pablo");
params.put("var2", "Luis");
model.fromMap(params);
ProcessInstance<? extends Model> processInstance = p.createInstance(model);
processInstance.start();
Model result = processInstance.variables();
assertEquals("Hello Pablo! Script", result.toMap().get("var1"));
assertEquals("Luis Script 2", result.toMap().get("var2"));
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AdHocFragmentsTest method testStartUserTask.
@Test
void testStartUserTask() throws Exception {
String taskName = "AdHoc User Task";
Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.AdHocFragments_1_0");
ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
processInstance.start();
Optional<WorkItem> workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isNotPresent();
processInstance.send(Sig.of(taskName, p.createModel()));
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isPresent();
assertThat(workItem.get().getId()).isNotBlank();
assertThat(workItem.get().getName()).isNotBlank();
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AdHocFragmentsTest method testStartFragments.
@Test
void testStartFragments() throws Exception {
Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.AdHocFragments_1_0");
ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
processInstance.start();
Map<String, Object> params = new HashMap<>();
params.put("user", "Juan");
processInstance.send(Sig.of("Service Task", params));
Model result = processInstance.variables();
assertEquals("Hello Juan 5!", result.toMap().get("var1"));
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class AdHocSubProcessTest method testCompletionAdHoc.
@Test
void testCompletionAdHoc() throws Exception {
Application app = generateCodeProcessesOnly("cases/CompletionAdHoc.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.CompletionAdHoc_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "yellow");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems.size()).isEqualTo(1);
WorkItem workItem = workItems.get(0);
workItem.getParameters().put("favouriteColour", "green");
params.put("favouriteColour", "green");
processInstance.completeWorkItem(workItem.getId(), params);
assertState(processInstance, ProcessInstance.STATE_COMPLETED);
}
Aggregations