Search in sources :

Example 1 with CommentEventBody

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

the class UserTaskInstanceDataEventCodecTest 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.getKogitoUserTaskinstanceId(), doc.get("kogitoUserTaskinstanceId"));
        assertEquals(event.getKogitoUserTaskinstanceState(), doc.get("kogitoUserTaskinstanceState"));
        assertEquals(event.getData().getId(), ((Document) doc.get("data")).get("id"));
        assertEquals(event.getData().getTaskName(), ((Document) doc.get("data")).get("taskName"));
        assertEquals(event.getData().getTaskDescription(), ((Document) doc.get("data")).get("taskDescription"));
        assertEquals(event.getData().getTaskPriority(), ((Document) doc.get("data")).get("taskPriority"));
        assertEquals(event.getData().getReferenceName(), ((Document) doc.get("data")).get("referenceName"));
        assertEquals(event.getData().getStartDate(), ((Document) doc.get("data")).get("startDate"));
        assertEquals(event.getData().getCompleteDate(), ((Document) doc.get("data")).get("completeDate"));
        assertEquals(event.getData().getState(), ((Document) doc.get("data")).get("state"));
        assertEquals(event.getData().getActualOwner(), ((Document) doc.get("data")).get("actualOwner"));
        assertEquals(event.getData().getPotentialUsers(), ((Document) doc.get("data")).get("potentialUsers"));
        assertEquals(event.getData().getPotentialGroups(), ((Document) doc.get("data")).get("potentialGroups"));
        assertEquals(event.getData().getExcludedUsers(), ((Document) doc.get("data")).get("excludedUsers"));
        assertEquals(event.getData().getAdminUsers(), ((Document) doc.get("data")).get("adminUsers"));
        assertEquals(event.getData().getAdminGroups(), ((Document) doc.get("data")).get("adminGroups"));
        assertEquals(new Document(event.getData().getInputs()), ((Document) doc.get("data")).get("inputs"));
        assertEquals(new Document(event.getData().getOutputs()), ((Document) doc.get("data")).get("outputs"));
        assertEquals(event.getData().getProcessInstanceId(), ((Document) doc.get("data")).get("processInstanceId"));
        assertEquals(event.getData().getRootProcessInstanceId(), ((Document) doc.get("data")).get("rootProcessInstanceId"));
        assertEquals(event.getData().getProcessId(), ((Document) doc.get("data")).get("processId"));
        assertEquals(event.getData().getRootProcessId(), ((Document) doc.get("data")).get("rootProcessId"));
        CommentEventBody c = event.getData().getComments().iterator().next();
        Document comment = new Document().append("id", c.getId()).append("content", c.getContent()).append("updatedAt", c.getUpdatedAt()).append("updatedBy", c.getUpdatedBy());
        Set<Document> comments = new HashSet<>();
        comments.add(comment);
        assertEquals(comments, ((Document) doc.get("data")).get("comments"));
        AttachmentEventBody a = event.getData().getAttachments().iterator().next();
        Document attachment = new Document().append("id", a.getId()).append("content", a.getContent()).append("updatedAt", a.getUpdatedAt()).append("updatedBy", a.getUpdatedBy()).append("name", a.getName());
        Set<Document> attachments = new HashSet<>();
        attachments.add(attachment);
        assertEquals(attachments, ((Document) doc.get("data")).get("attachments"));
    }
}
Also used : EncoderContext(org.bson.codecs.EncoderContext) BsonWriter(org.bson.BsonWriter) CommentEventBody(org.kie.kogito.event.process.CommentEventBody) Document(org.bson.Document) AttachmentEventBody(org.kie.kogito.event.process.AttachmentEventBody) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with CommentEventBody

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

the class UserTaskInstanceDataEventCodecTest method setUp.

@BeforeEach
void setUp() {
    codec = new UserTaskInstanceDataEventCodec();
    String source = "testSource";
    String kogitoAddons = "testKogitoAddons";
    CommentEventBody comment = CommentEventBody.create().id("testCommentId").updatedBy("testCommentUpdatedBy").content("testCommentContent").updatedAt(new Date()).build();
    Set<CommentEventBody> comments = Collections.singleton(comment);
    AttachmentEventBody attachment = AttachmentEventBody.create().id("testAttachmentId").updatedBy("testAttachmentUpdatedBy").content(URI.create("test.attachment.test")).name("testAttachmentName").updatedAt(new Date()).build();
    Set<AttachmentEventBody> attachments = Collections.singleton(attachment);
    Map<String, String> metaData = new HashMap<>();
    metaData.put(ProcessInstanceEventBody.ID_META_DATA, "testKogitoProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.ROOT_ID_META_DATA, "testKogitoRootProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.PROCESS_ID_META_DATA, "testKogitoProcessId");
    metaData.put(ProcessInstanceEventBody.ROOT_PROCESS_ID_META_DATA, "testKogitoRootProcessId");
    metaData.put(UserTaskInstanceEventBody.UT_STATE_META_DATA, "testKogitoUserTaskinstanceState");
    metaData.put(UserTaskInstanceEventBody.UT_ID_META_DATA, "testKogitoUserTaskinstanceId");
    UserTaskInstanceEventBody body = UserTaskInstanceEventBody.create().id("testId").taskName("testTaskName").taskDescription("testTaskDescription").taskPriority("testTaskPriority").referenceName("testReferenceName").startDate(new Date()).completeDate(new Date()).state("testState").actualOwner("testActualOwner").potentialUsers(Collections.singleton("testPotentialUsers")).potentialGroups(Collections.singleton("testPotentialGroups")).excludedUsers(Collections.singleton("testExcludedUsers")).adminUsers(Collections.singleton("testAdminUsers")).adminGroups(Collections.singleton("testAdminGroups")).inputs(Collections.singletonMap("testInputsKey", "testInputsValue")).outputs(Collections.singletonMap("testOutputsKey", "testOutputsValue")).processInstanceId("testKogitoProcessinstanceId").rootProcessInstanceId("testKogitoRootProcessinstanceId").processId("testKogitoProcessId").rootProcessId("testKogitoRootProcessId").comments(comments).attachments(attachments).build();
    event = new UserTaskInstanceDataEvent(source, kogitoAddons, metaData, body);
}
Also used : HashMap(java.util.HashMap) CommentEventBody(org.kie.kogito.event.process.CommentEventBody) UserTaskInstanceEventBody(org.kie.kogito.event.process.UserTaskInstanceEventBody) BsonString(org.bson.BsonString) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) AttachmentEventBody(org.kie.kogito.event.process.AttachmentEventBody) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AttachmentEventBody (org.kie.kogito.event.process.AttachmentEventBody)2 CommentEventBody (org.kie.kogito.event.process.CommentEventBody)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BsonString (org.bson.BsonString)1 BsonWriter (org.bson.BsonWriter)1 Document (org.bson.Document)1 EncoderContext (org.bson.codecs.EncoderContext)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 UserTaskInstanceDataEvent (org.kie.kogito.event.process.UserTaskInstanceDataEvent)1 UserTaskInstanceEventBody (org.kie.kogito.event.process.UserTaskInstanceEventBody)1