Search in sources :

Example 51 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseWithExtraTaskFromRules.

@Test
public void testCarInsuranceClaimCaseWithExtraTaskFromRules() {
    // 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();
        // ask for more details from insured
        caseService.addDataToCaseFile(CAR_INS_CASE_ID, "decision", "AskForDetails");
        assertAndProvideAdditionalDetails();
        // let's trigger claim offer calculation
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Calculate claim", null);
        // now we have another task for insured as claim was calculated
        // let's accept the calculated claim
        assertAndAcceptClaimOffer();
        // 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());
        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 : 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 52 with QueryContext

use of org.kie.api.runtime.query.QueryContext 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 53 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method assertBuildClaimReportStage.

protected void assertBuildClaimReportStage() {
    Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(CAR_INS_CASE_ID, true, new QueryContext());
    assertEquals(1, activeStages.size());
    CaseStageInstance stage = activeStages.iterator().next();
    assertEquals("Build claim report", stage.getName());
}
Also used : CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext)

Example 54 with QueryContext

use of org.kie.api.runtime.query.QueryContext 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 55 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCase.

@Test
public void testCarInsuranceClaimCase() {
    // 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();
        // let's trigger claim offer calculation
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Calculate claim", null);
        // now we have another task for insured as claim was calculated
        // let's accept the calculated claim
        assertAndAcceptClaimOffer();
        // 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());
        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 : 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)

Aggregations

QueryContext (org.kie.api.runtime.query.QueryContext)315 Test (org.junit.Test)299 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)131 HashMap (java.util.HashMap)115 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)109 ArrayList (java.util.ArrayList)99 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)67 RequestInfo (org.kie.api.executor.RequestInfo)53 TaskSummary (org.kie.api.task.model.TaskSummary)53 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)51 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)45 CommandContext (org.kie.api.executor.CommandContext)39 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)37 UserImpl (org.jbpm.services.task.impl.model.UserImpl)37 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)36 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)34 QueryFilter (org.kie.internal.query.QueryFilter)30 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)29 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)29