Search in sources :

Example 1 with MilestoneEventBody

use of org.kie.kogito.event.process.MilestoneEventBody in project kogito-runtimes by kiegroup.

the class ProcessInstanceDataEventCodecTest method encode.

@Test
void encode() {
    try (MockedStatic<CodecUtils> codecUtils = mockStatic(CodecUtils.class)) {
        Codec<Document> mockCodec = mock(Codec.class);
        codecUtils.when(CodecUtils::codec).thenReturn(mockCodec);
        codecUtils.when(() -> CodecUtils.encodeDataEvent(any(), any())).thenCallRealMethod();
        BsonWriter writer = mock(BsonWriter.class);
        EncoderContext context = EncoderContext.builder().build();
        codec.encode(writer, event, context);
        ArgumentCaptor<Document> captor = ArgumentCaptor.forClass(Document.class);
        verify(mockCodec, times(1)).encode(eq(writer), captor.capture(), eq(context));
        Document doc = captor.getValue();
        assertEquals(event.getId(), doc.get(ID));
        assertEquals(event.getSpecVersion().toString(), doc.get("specversion"));
        assertEquals(event.getSource().toString(), doc.get("source"));
        assertEquals(event.getType(), doc.get("type"));
        assertEquals(event.getTime(), doc.get("time"));
        assertEquals(event.getSubject(), doc.get("subject"));
        assertEquals(event.getDataContentType(), doc.get("dataContentType"));
        assertEquals(event.getDataSchema(), doc.get("dataSchema"));
        assertEquals(event.getKogitoProcessinstanceId(), doc.get("kogitoProcessinstanceId"));
        assertEquals(event.getKogitoRootProcessinstanceId(), doc.get("kogitoRootProcessinstanceId"));
        assertEquals(event.getKogitoProcessId(), doc.get("kogitoProcessId"));
        assertEquals(event.getKogitoRootProcessId(), doc.get("kogitoRootProcessId"));
        assertEquals(event.getKogitoAddons(), doc.get("kogitoAddons"));
        assertEquals(event.getKogitoParentProcessinstanceId(), doc.get("kogitoParentProcessinstanceId"));
        assertEquals(event.getKogitoProcessinstanceState(), doc.get("kogitoProcessinstanceState"));
        assertEquals(event.getKogitoReferenceId(), doc.get("kogitoReferenceId"));
        assertEquals(event.getKogitoStartFromNode(), doc.get("kogitoStartFromNode"));
        assertEquals(event.getData().getId(), ((Document) doc.get("data")).get("id"));
        assertEquals(event.getData().getParentInstanceId(), ((Document) doc.get("data")).get("parentInstanceId"));
        assertEquals(event.getData().getRootInstanceId(), ((Document) doc.get("data")).get("rootInstanceId"));
        assertEquals(event.getData().getProcessId(), ((Document) doc.get("data")).get("processId"));
        assertEquals(event.getData().getRootProcessId(), ((Document) doc.get("data")).get("rootProcessId"));
        assertEquals(event.getData().getProcessName(), ((Document) doc.get("data")).get("processName"));
        assertEquals(event.getData().getStartDate(), ((Document) doc.get("data")).get("startDate"));
        assertEquals(event.getData().getEndDate(), ((Document) doc.get("data")).get("endDate"));
        assertEquals(event.getData().getState(), ((Document) doc.get("data")).get("state"));
        assertEquals(event.getData().getBusinessKey(), ((Document) doc.get("data")).get("businessKey"));
        assertEquals(event.getData().getRoles(), ((Document) doc.get("data")).get("roles"));
        assertEquals(new Document(event.getData().getVariables()), ((Document) doc.get("data")).get("variables"));
        Document error = new Document().append("errorMessage", event.getData().getError().getErrorMessage()).append("nodeDefinitionId", event.getData().getError().getNodeDefinitionId());
        assertEquals(error, ((Document) doc.get("data")).get("error"));
        NodeInstanceEventBody ni = event.getData().getNodeInstances().iterator().next();
        Document nodeInstance = new Document().append("id", ni.getId()).append("nodeId", ni.getNodeId()).append("nodeDefinitionId", ni.getNodeDefinitionId()).append("nodeName", ni.getNodeName()).append("nodeType", ni.getNodeType()).append("triggerTime", ni.getTriggerTime()).append("leaveTime", ni.getLeaveTime());
        Set<Document> nodeInstances = new HashSet<>();
        nodeInstances.add(nodeInstance);
        assertEquals(nodeInstances, ((Document) doc.get("data")).get("nodeInstances"));
        MilestoneEventBody mi = event.getData().getMilestones().iterator().next();
        Document milestone = new Document().append("id", mi.getId()).append("name", mi.getName()).append("status", mi.getStatus());
        Set<Document> milestones = new HashSet<>();
        milestones.add(milestone);
        assertEquals(milestones, ((Document) doc.get("data")).get("milestones"));
    }
}
Also used : EncoderContext(org.bson.codecs.EncoderContext) BsonWriter(org.bson.BsonWriter) NodeInstanceEventBody(org.kie.kogito.event.process.NodeInstanceEventBody) MilestoneEventBody(org.kie.kogito.event.process.MilestoneEventBody) Document(org.bson.Document) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with MilestoneEventBody

use of org.kie.kogito.event.process.MilestoneEventBody in project kogito-runtimes by kiegroup.

the class PublishEventIT 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.get(Processes.class).processById("TestCase.SimpleMilestone");
    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.getKogitoProcessinstanceId()).isNotNull();
    assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("TestCase.SimpleMilestone");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    assertThat(processDataEvent.getSource().toString()).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 : UnitOfWork(org.kie.kogito.uow.UnitOfWork) MilestoneEventBody(org.kie.kogito.event.process.MilestoneEventBody) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Status(org.kie.kogito.process.flexible.ItemDescription.Status) Person(org.kie.kogito.codegen.data.Person) ArrayList(java.util.ArrayList) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) UserTaskInstanceEventBody(org.kie.kogito.event.process.UserTaskInstanceEventBody) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) ProcessInstanceEventBody(org.kie.kogito.event.process.ProcessInstanceEventBody) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) Map(java.util.Map) Process(org.kie.kogito.process.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Set(java.util.Set) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Application(org.kie.kogito.Application) Collectors(java.util.stream.Collectors) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) EventPublisher(org.kie.kogito.event.EventPublisher) ProcessError(org.kie.kogito.process.ProcessError) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DataEvent(org.kie.kogito.event.DataEvent) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) UnitOfWork(org.kie.kogito.uow.UnitOfWork) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) Processes(org.kie.kogito.process.Processes) MilestoneEventBody(org.kie.kogito.event.process.MilestoneEventBody) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with MilestoneEventBody

use of org.kie.kogito.event.process.MilestoneEventBody 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)

Aggregations

Test (org.junit.jupiter.api.Test)3 MilestoneEventBody (org.kie.kogito.event.process.MilestoneEventBody)3 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 BsonWriter (org.bson.BsonWriter)1 Document (org.bson.Document)1 EncoderContext (org.bson.codecs.EncoderContext)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1