Search in sources :

Example 1 with Milestone

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);
}
Also used : KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) Milestone(org.kie.kogito.process.flexible.Milestone) MilestoneEventBody(org.kie.kogito.event.process.MilestoneEventBody) Test(org.junit.jupiter.api.Test)

Example 2 with Milestone

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());
}
Also used : HashMap(java.util.HashMap) Milestone(org.kie.kogito.process.flexible.Milestone) ArrayList(java.util.ArrayList) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with Milestone

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());
}
Also used : Milestone(org.kie.kogito.process.flexible.Milestone) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessTestUtils.assertState(org.kie.kogito.process.impl.ProcessTestUtils.assertState) ArrayList(java.util.ArrayList) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) Map(java.util.Map) Process(org.kie.kogito.process.Process) AVAILABLE(org.kie.kogito.process.flexible.ItemDescription.Status.AVAILABLE) Metadata(org.jbpm.ruleflow.core.Metadata) Collection(java.util.Collection) Application(org.kie.kogito.Application) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) COMPLETED(org.kie.kogito.process.flexible.ItemDescription.Status.COMPLETED) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) Milestone(org.kie.kogito.process.flexible.Milestone) ArrayList(java.util.ArrayList) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 Milestone (org.kie.kogito.process.flexible.Milestone)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Application (org.kie.kogito.Application)2 Model (org.kie.kogito.Model)2 Processes (org.kie.kogito.process.Processes)2 WorkItem (org.kie.kogito.process.WorkItem)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Metadata (org.jbpm.ruleflow.core.Metadata)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)1