Search in sources :

Example 1 with NodeInstanceEventBody

use of org.kie.kogito.services.event.impl.NodeInstanceEventBody 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

HashSet (java.util.HashSet)1 BsonWriter (org.bson.BsonWriter)1 Document (org.bson.Document)1 EncoderContext (org.bson.codecs.EncoderContext)1 Test (org.junit.jupiter.api.Test)1 MilestoneEventBody (org.kie.kogito.services.event.impl.MilestoneEventBody)1 NodeInstanceEventBody (org.kie.kogito.services.event.impl.NodeInstanceEventBody)1