use of org.kie.kogito.event.process.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"));
}
}
use of org.kie.kogito.event.process.NodeInstanceEventBody in project kogito-runtimes by kiegroup.
the class ProcessInstanceEventBatch method handleProcessNodeLeftEvent.
protected void handleProcessNodeLeftEvent(ProcessNodeLeftEvent event, ProcessInstanceEventBody body) {
NodeInstanceEventBody nodeInstanceBody = create(event);
// if it's already there, remove it
body.getNodeInstances().remove(nodeInstanceBody);
// and add it back as the node left event has latest information
body.update().nodeInstance(nodeInstanceBody);
}
Aggregations