Search in sources :

Example 31 with CaseInstance

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

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseCloseCaseFromRulesViaBusinessTask.

@Test
public void testCarInsuranceClaimCaseCloseCaseFromRulesViaBusinessTask() {
    // let's assign users to roles so they can be participants in the case
    String caseId = startAndAssertCaseInstance(deploymentUnit.getIdentifier(), "john", "mary");
    try {
        // let's verify case is created
        assertCaseInstance(deploymentUnit.getIdentifier(), CAR_INS_CASE_ID);
        // let's look at what stages are active
        assertBuildClaimReportStage();
        // since the first task assigned to insured is with auto start it should be already active
        // the same task can be claimed by insuranceRepresentative in case claim is reported over phone
        long taskId = assertBuildClaimReportAvailableForBothRoles();
        // let's provide claim report with initial data
        // claim report should be stored in case file data
        ClaimReport claimReport = new ClaimReport();
        claimReport.setName("John Doe");
        claimReport.setAddress("Main street, NY");
        claimReport.setAccidentDescription(null);
        claimReport.setAccidentDate(new Date());
        Map<String, Object> params = new HashMap<>();
        params.put("claimReport_", claimReport);
        userTaskService.completeAutoProgress(taskId, "john", params);
        // let's complete the stage by explicitly stating that claimReport is done
        caseService.addDataToCaseFile(CAR_INS_CASE_ID, "claimReportDone", true);
        // there should be no process instances for the case
        Collection<ProcessInstanceDesc> caseProcesInstances = caseRuntimeDataService.getProcessInstancesForCase(CAR_INS_CASE_ID, Arrays.asList(ProcessInstance.STATE_ACTIVE), new QueryContext());
        assertEquals(0, caseProcesInstances.size());
        CaseInstance cInstance = caseRuntimeDataService.getCaseInstanceById(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("Invalid case data", cInstance.getCompletionMessage());
        caseId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) ClaimReport(org.jbpm.casemgmt.demo.insurance.ClaimReport) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Date(java.util.Date) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 32 with CaseInstance

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

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseCloseCaseFromRulesViaProcess.

@Test
public void testCarInsuranceClaimCaseCloseCaseFromRulesViaProcess() {
    // let's assign users to roles so they can be participants in the case
    String caseId = startAndAssertCaseInstance(deploymentUnit.getIdentifier(), "john", "mary");
    try {
        // let's verify case is created
        assertCaseInstance(deploymentUnit.getIdentifier(), CAR_INS_CASE_ID);
        // let's look at what stages are active
        assertBuildClaimReportStage();
        // since the first task assigned to insured is with auto start it should be already active
        // the same task can be claimed by insuranceRepresentative in case claim is reported over phone
        long taskId = assertBuildClaimReportAvailableForBothRoles();
        // let's provide claim report with initial data
        // claim report should be stored in case file data
        provideAndAssertClaimReport(taskId);
        // now we have another task for insured to provide property damage report
        taskId = assertPropertyDamageReportAvailableForBothRoles();
        // let's provide the property damage report
        provideAndAssertPropertyDamageReport(taskId);
        // let's complete the stage by explicitly stating that claimReport is done
        caseService.addDataToCaseFile(CAR_INS_CASE_ID, "claimReportDone", true);
        // we should be in another stage - Claim assessment
        assertClaimAssesmentStage();
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("caseFile_CaseAction", "Close");
        caseService.addDynamicSubprocess(CAR_INS_CASE_ID, SUBPROCESS_P_ID, parameters);
        // there should be no process instances for the case
        Collection<ProcessInstanceDesc> caseProcesInstances = caseRuntimeDataService.getProcessInstancesForCase(CAR_INS_CASE_ID, Arrays.asList(ProcessInstance.STATE_ACTIVE), new QueryContext());
        assertEquals(0, caseProcesInstances.size());
        CaseInstance cInstance = caseRuntimeDataService.getCaseInstanceById(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("Closing case from rules", cInstance.getCompletionMessage());
        caseId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 33 with CaseInstance

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

the class CaseAssignmentServiceImplTest method testProperRoleAssigned.

@Test
public void testProperRoleAssigned() {
    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).assignGroup("generalRole", "managers");
    ((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();
        userTaskService.completeAutoProgress(foundTask.getId(), "mary", new HashMap<>());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertEquals(1, tasks.size());
    } 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 34 with CaseInstance

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

use of org.jbpm.casemgmt.api.model.instance.CaseInstance 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)

Aggregations

CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)92 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)88 Test (org.junit.Test)88 HashMap (java.util.HashMap)73 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)66 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)47 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)47 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)47 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)47 UserImpl (org.jbpm.services.task.impl.model.UserImpl)47 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)46 TaskSummary (org.kie.api.task.model.TaskSummary)42 QueryFilter (org.kie.internal.query.QueryFilter)29 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)12 ArrayList (java.util.ArrayList)10 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)10 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)10