Search in sources :

Example 1 with TestNotificationPublisher

use of org.jbpm.casemgmt.impl.util.TestNotificationPublisher in project jbpm by kiegroup.

the class CaseCommentNotificationTest method testCommentsNotificationWithoutTemplate.

@Test
public void testCommentsNotificationWithoutTemplate() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    TestNotificationPublisher publisher = new TestNotificationPublisher(true);
    CommentNotificationEventListener listener = CommentNotificationEventListenerFactory.get("test");
    listener.addPublisher(publisher);
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(0, caseComments.size());
        caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment refering to @owner");
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        CommentInstance comment = caseComments.iterator().next();
        assertComment(comment, "poul", "just a tiny comment refering to @owner");
        String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with body just a tiny comment refering to john";
        List<String> published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
        caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        comment = caseComments.iterator().next();
        assertComment(comment, "poul", "Updated just a tiny comment refering to @owner");
        expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with body Updated just a tiny comment refering to john";
        published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CommentNotificationEventListener(org.jbpm.casemgmt.impl.event.CommentNotificationEventListener) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 2 with TestNotificationPublisher

use of org.jbpm.casemgmt.impl.util.TestNotificationPublisher in project jbpm by kiegroup.

the class CaseCommentNotificationTest method testCommentsNotificationWithTemplate.

@Test
public void testCommentsNotificationWithTemplate() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    TestNotificationPublisher publisher = new TestNotificationPublisher(false);
    CommentNotificationEventListener listener = CommentNotificationEventListenerFactory.get("test");
    listener.addPublisher(publisher);
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(0, caseComments.size());
        caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment refering to @owner");
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        CommentInstance comment = caseComments.iterator().next();
        assertComment(comment, "poul", "just a tiny comment refering to @owner");
        String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
        List<String> published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
        caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
        caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
        assertNotNull(caseComments);
        assertEquals(1, caseComments.size());
        comment = caseComments.iterator().next();
        assertComment(comment, "poul", "Updated just a tiny comment refering to @owner");
        expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
        published = publisher.get();
        assertThat(published).hasSize(1);
        assertThat(published.get(0)).isEqualTo(expectedNotification);
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CommentNotificationEventListener(org.jbpm.casemgmt.impl.event.CommentNotificationEventListener) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 3 with TestNotificationPublisher

use of org.jbpm.casemgmt.impl.util.TestNotificationPublisher in project jbpm by kiegroup.

the class CommentNotificationEventListenerTest method testNotificationOnCommentAddedWithRawBody.

@Test
public void testNotificationOnCommentAddedWithRawBody() {
    CommentNotificationEventListener listener = new CommentNotificationEventListener();
    List<String> mentionedRoles = new ArrayList<>();
    mentionedRoles.add("owner");
    mentionedRoles.add("manager");
    CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
    CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
    CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
    TestNotificationPublisher publisher = new TestNotificationPublisher(true);
    listener.addPublisher(publisher);
    listener.afterCaseCommentAdded(event);
    String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-00001) comment to [[UserImpl:'mary'], [UserImpl:'john']] with body simple comment for john and mary";
    List<String> published = publisher.get();
    assertThat(published).hasSize(1);
    assertThat(published.get(0)).isEqualTo(expectedNotification);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with TestNotificationPublisher

use of org.jbpm.casemgmt.impl.util.TestNotificationPublisher in project jbpm by kiegroup.

the class CommentNotificationEventListenerTest method testNotificationOnCommentAdded.

@Test
public void testNotificationOnCommentAdded() {
    CommentNotificationEventListener listener = new CommentNotificationEventListener();
    List<String> mentionedRoles = new ArrayList<>();
    mentionedRoles.add("owner");
    mentionedRoles.add("manager");
    CaseFileInstance caseFile = buildCaseFile(mentionedRoles);
    CommentInstanceImpl comment = new CommentInstanceImpl("john", "simple comment for @owner and @manager", new ArrayList<>());
    CaseCommentEvent event = new CaseCommentEvent("john", caseFile.getCaseId(), caseFile, comment);
    TestNotificationPublisher publisher = new TestNotificationPublisher(false);
    listener.addPublisher(publisher);
    listener.afterCaseCommentAdded(event);
    String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-00001) comment to [[UserImpl:'mary'], [UserImpl:'john']] with template mentioned-in-comment";
    List<String> published = publisher.get();
    assertThat(published).hasSize(1);
    assertThat(published.get(0)).isEqualTo(expectedNotification);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseCommentEvent(org.jbpm.casemgmt.api.event.CaseCommentEvent) TestNotificationPublisher(org.jbpm.casemgmt.impl.util.TestNotificationPublisher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)4 TestNotificationPublisher (org.jbpm.casemgmt.impl.util.TestNotificationPublisher)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CaseCommentEvent (org.jbpm.casemgmt.api.event.CaseCommentEvent)2 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)2 CommentInstance (org.jbpm.casemgmt.api.model.instance.CommentInstance)2 CommentNotificationEventListener (org.jbpm.casemgmt.impl.event.CommentNotificationEventListener)2 CommentInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl)2 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)2 UserImpl (org.jbpm.services.task.impl.model.UserImpl)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2