Search in sources :

Example 1 with MilestoneEventBody

use of org.kie.kogito.services.event.impl.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) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) HashMap(java.util.HashMap) Status(org.kie.kogito.process.flexible.ItemDescription.Status) Person(org.kie.kogito.codegen.data.Person) ArrayList(java.util.ArrayList) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Map(java.util.Map) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Process(org.kie.kogito.process.Process) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Assertions.tuple(org.assertj.core.api.Assertions.tuple) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Set(java.util.Set) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Application(org.kie.kogito.Application) 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) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) 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.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with MilestoneEventBody

use of org.kie.kogito.services.event.impl.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.services.event.impl.NodeInstanceEventBody) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) Document(org.bson.Document) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 MilestoneEventBody (org.kie.kogito.services.event.impl.MilestoneEventBody)2 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 Set (java.util.Set)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 Application (org.kie.kogito.Application)1 Model (org.kie.kogito.Model)1 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)1