Search in sources :

Example 1 with Milestone

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);
}
Also used : ProcessInstanceEventBatch(io.automatiko.engine.services.event.impl.ProcessInstanceEventBatch) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Test(org.junit.jupiter.api.Test)

Example 2 with Milestone

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());
}
Also used : HashMap(java.util.HashMap) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 3 with Milestone

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());
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Metadata(io.automatiko.engine.workflow.process.executable.core.Metadata) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) COMPLETED(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED) ArrayList(java.util.ArrayList) Application(io.automatiko.engine.api.Application) Map(java.util.Map) Process(io.automatiko.engine.api.workflow.Process) Model(io.automatiko.engine.api.Model) Collection(java.util.Collection) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ProcessTestUtils.assertState(io.automatiko.engine.codegen.tests.ProcessTestUtils.assertState) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AVAILABLE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) ArrayList(java.util.ArrayList) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Milestone (io.automatiko.engine.api.workflow.flexible.Milestone)3 Test (org.junit.jupiter.api.Test)3 Application (io.automatiko.engine.api.Application)2 Model (io.automatiko.engine.api.Model)2 WorkItem (io.automatiko.engine.api.workflow.WorkItem)2 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 Process (io.automatiko.engine.api.workflow.Process)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 AVAILABLE (io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE)1 COMPLETED (io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED)1 ProcessTestUtils.assertState (io.automatiko.engine.codegen.tests.ProcessTestUtils.assertState)1 MilestoneEventBody (io.automatiko.engine.services.event.impl.MilestoneEventBody)1 ProcessInstanceEventBatch (io.automatiko.engine.services.event.impl.ProcessInstanceEventBatch)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 Metadata (io.automatiko.engine.workflow.process.executable.core.Metadata)1 ExecutableProcessInstance (io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance)1 Collection (java.util.Collection)1