Search in sources :

Example 1 with MilestoneEventBody

use of io.automatiko.engine.services.event.impl.MilestoneEventBody 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 MilestoneEventBody

use of io.automatiko.engine.services.event.impl.MilestoneEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest method testProcessWithMilestoneEvents.

@Test
public void testProcessWithMilestoneEvents() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.processes().processById("TestCase.SimpleMilestone_1_0");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    DataEvent<?> event = events.get(0);
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
    assertThat(processDataEvent.getSource()).isEqualTo("http://myhost/SimpleMilestone");
    Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
    assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) UserTaskInstanceEventBody(io.automatiko.engine.services.event.impl.UserTaskInstanceEventBody) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) HashMap(java.util.HashMap) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) Application(io.automatiko.engine.api.Application) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Map(java.util.Map) StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventPublisher(io.automatiko.engine.api.event.EventPublisher) Model(io.automatiko.engine.api.Model) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) Status(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status) Set(java.util.Set) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) Test(org.junit.jupiter.api.Test) List(java.util.List) WorkItem(io.automatiko.engine.api.workflow.WorkItem) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

MilestoneEventBody (io.automatiko.engine.services.event.impl.MilestoneEventBody)2 Test (org.junit.jupiter.api.Test)2 Application (io.automatiko.engine.api.Application)1 Model (io.automatiko.engine.api.Model)1 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)1 DataEvent (io.automatiko.engine.api.event.DataEvent)1 EventPublisher (io.automatiko.engine.api.event.EventPublisher)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)1 Process (io.automatiko.engine.api.workflow.Process)1 ProcessErrors (io.automatiko.engine.api.workflow.ProcessErrors)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 Status (io.automatiko.engine.api.workflow.flexible.ItemDescription.Status)1 Milestone (io.automatiko.engine.api.workflow.flexible.Milestone)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)1 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)1 ProcessInstanceEventBatch (io.automatiko.engine.services.event.impl.ProcessInstanceEventBatch)1 ProcessInstanceEventBody (io.automatiko.engine.services.event.impl.ProcessInstanceEventBody)1