use of io.automatiko.engine.api.workflow.flexible.Milestone in project automatiko-engine by automatiko-io.
the class ProcessInstanceEventBatchTest method testMilestones.
@Test
public void testMilestones() {
ProcessInstanceEventBatch batch = new ProcessInstanceEventBatch(null, null);
WorkflowProcessInstance pi = mock(WorkflowProcessInstance.class);
when(pi.milestones()).thenReturn(null);
assertThat(batch.createMilestones(pi)).isNull();
when(pi.milestones()).thenReturn(emptyList());
assertThat(batch.createMilestones(pi)).isEmpty();
Milestone milestone = Milestone.builder().withId("id").withName("name").withStatus(Status.AVAILABLE).build();
when(pi.milestones()).thenReturn(singleton(milestone));
MilestoneEventBody milestoneEventBody = MilestoneEventBody.create().id("id").name("name").status(Status.AVAILABLE.name()).build();
assertThat(batch.createMilestones(pi)).containsOnly(milestoneEventBody);
}
use of io.automatiko.engine.api.workflow.flexible.Milestone in project automatiko-engine by automatiko-io.
the class MilestoneTest method testConditionalMilestone.
@Test
void testConditionalMilestone() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/ConditionalMilestone.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.ConditionalMilestone_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "orange");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
Collection<Milestone> expected = new ArrayList<>();
expected.add(Milestone.builder().withName("Milestone").withStatus(AVAILABLE).build());
assertMilestones(expected, processInstance.milestones());
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(AVAILABLE).build()).collect(Collectors.toList());
assertMilestones(expected, processInstance.milestones());
List<WorkItem> workItems = processInstance.workItems();
params.put("favouriteColour", "blue");
processInstance.completeWorkItem(workItems.get(0).getId(), params);
expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(COMPLETED).build()).collect(Collectors.toList());
assertMilestones(expected, processInstance.milestones());
}
use of io.automatiko.engine.api.workflow.flexible.Milestone in project automatiko-engine by automatiko-io.
the class MilestoneTest method testSimpleMilestone.
@Test
void testSimpleMilestone() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.SimpleMilestone_1_0");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
assertState(processInstance, ProcessInstance.STATE_PENDING);
Collection<Milestone> expected = new ArrayList<>();
expected.add(Milestone.builder().withName("AutoStartMilestone").withStatus(AVAILABLE).build());
expected.add(Milestone.builder().withName("SimpleMilestone").withStatus(AVAILABLE).build());
assertMilestones(expected, processInstance.milestones());
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_COMPLETED);
expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(COMPLETED).build()).collect(Collectors.toList());
assertMilestones(expected, processInstance.milestones());
ExecutableProcessInstance legacyProcessInstance = (ExecutableProcessInstance) ((AbstractProcessInstance<?>) processInstance).processInstance();
assertThat(legacyProcessInstance.getNodeInstances()).isEmpty();
Optional<String> milestoneId = Stream.of(legacyProcessInstance.getNodeContainer().getNodes()).filter(node -> node.getName().equals("SimpleMilestone")).map(n -> (String) n.getMetaData().get(Metadata.UNIQUE_ID)).findFirst();
assertTrue(milestoneId.isPresent());
assertThat(legacyProcessInstance.getCompletedNodeIds()).contains(milestoneId.get());
}
Aggregations