Search in sources :

Example 46 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseAssignmentServiceImplTest method testRoleAssignedMissingUser.

@Test
public void testRoleAssignedMissingUser() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("actorRole", new UserImpl("mary"));
    roleAssignments.put("groupRole", new GroupImpl("managers"));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), CASE_Y_P_ID, data, roleAssignments);
    ((CaseAssignment) caseFile).assignUser("generalRole", "john");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), CASE_Y_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());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "mary", null, new QueryContext());
        assertEquals(5, tasks.size());
        TaskSummary foundTask = tasks.stream().filter(task -> task.getName().equals("Task E")).findFirst().get();
        assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
            userTaskService.completeAutoProgress(foundTask.getId(), "mary", new HashMap<>());
        }).withMessageContaining("Case role 'generalRole' has no matching assignments");
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 47 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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 48 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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 49 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddDynamicUserTaskToEmptyStage.

@Test
public void testAddDynamicUserTaskToEmptyStage() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary insideTask = tasks.get(0);
    assertThat(insideTask.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 50 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddMultipleDynamicTasksToStage.

@Test
public void testAddMultipleDynamicTasksToStage() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(2);
    TaskSummary userTask1 = tasks.get(0);
    assertThat(userTask1.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(userTask1.getId(), USER, null);
    TaskSummary userTask2 = tasks.get(1);
    assertThat(userTask2.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(userTask2.getId(), USER, null);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)121 HashMap (java.util.HashMap)95 Test (org.junit.Test)86 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)81 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)66 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)61 UserImpl (org.jbpm.services.task.impl.model.UserImpl)54 QueryContext (org.kie.api.runtime.query.QueryContext)46 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)44 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)42 TaskSummary (org.kie.api.task.model.TaskSummary)40 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)39 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)39 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)39 QueryFilter (org.kie.internal.query.QueryFilter)26 ArrayList (java.util.ArrayList)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)20 Collection (java.util.Collection)17 List (java.util.List)17 Map (java.util.Map)16