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"));
}
}
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()));
}
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);
}
Aggregations