Search in sources :

Example 1 with AVAILABLE

use of org.kie.kogito.process.flexible.ItemDescription.Status.AVAILABLE 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

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)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 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Test (org.junit.jupiter.api.Test)1 Application (org.kie.kogito.Application)1 Model (org.kie.kogito.Model)1 AbstractCodegenIT (org.kie.kogito.codegen.AbstractCodegenIT)1 Process (org.kie.kogito.process.Process)1