use of org.kie.kogito.process.flexible.Milestone in project kogito-runtimes by kiegroup.
the class ProcessInstanceEventBatchTest method testMilestones.
@Test
public void testMilestones() {
ProcessInstanceEventBatch batch = new ProcessInstanceEventBatch(null, null);
KogitoWorkflowProcessInstance pi = mock(KogitoWorkflowProcessInstance.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 org.kie.kogito.process.flexible.Milestone in project kogito-runtimes by kiegroup.
the class MilestoneIT method testConditionalMilestone.
@Test
void testConditionalMilestone() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/ConditionalMilestone.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.ConditionalMilestone");
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 org.kie.kogito.process.flexible.Milestone in project kogito-runtimes by kiegroup.
the class MilestoneIT method testSimpleMilestone.
@Test
void testSimpleMilestone() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("TestCase.SimpleMilestone");
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());
RuleFlowProcessInstance legacyProcessInstance = (RuleFlowProcessInstance) ((AbstractProcessInstance<?>) processInstance).processInstance;
assertThat(legacyProcessInstance.getNodeInstances()).isEmpty();
assertThat(legacyProcessInstance.getNodeIdInError()).isNullOrEmpty();
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