use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartExpressionCaseWithCaseFile.
@Test
public void testStartExpressionCaseWithCaseFile() {
Map<String, Object> data = new HashMap<>();
data.put("person", new Person("john"));
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EXPRESSION_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EXPRESSION_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertNotNull(cInstance.getCaseFile());
assertEquals("john", ((Person) cInstance.getCaseFile().getData("person")).getName());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
Object personName = taskInputs.get("personName");
assertEquals("john", personName);
caseService.cancelCase(caseId);
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithSubCaseDestroySubCase.
@Test
public void testStartCaseWithSubCaseDestroySubCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("manager", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(SUB_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
caseService.triggerAdHocFragment(caseId, "Sub Case", null);
Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(2, caseInstances.size());
Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
assertTrue(byCaseId.containsKey(SUB_CASE_ID));
assertTrue(byCaseId.containsKey(HR_CASE_ID));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertNull(mainCaseFile.getData("subCaseId"));
caseService.destroyCase(HR_CASE_ID);
mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("subCaseId"));
assertEquals("John Doe", mainCaseFile.getData("outcome"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartProcessWithSubCaseDestroySubCase.
@Test
public void testStartProcessWithSubCaseDestroySubCase() {
Long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_TO_CASE_P_ID);
assertNotNull(processInstanceId);
try {
// check if case was created from within the process
CaseInstance cInstance = caseService.getCaseInstance(HR_CASE_ID);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertNull(processVariables.get("CaseId"));
assertNull(processVariables.get("outcome"));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
caseService.destroyCase(HR_CASE_ID);
processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertEquals(HR_CASE_ID, processVariables.get("CaseId"));
assertEquals("process2case", processVariables.get("outcome"));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Verify case results", tasks.get(0).getName());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
assertEquals(HR_CASE_ID, taskInputs.get("CaseId"));
assertEquals("process2case", taskInputs.get("outcome"));
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
ProcessInstanceDesc piLog = runtimeDataService.getProcessInstanceById(processInstanceId);
assertNotNull(piLog);
assertEquals(ProcessInstance.STATE_COMPLETED, piLog.getState().intValue());
processInstanceId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (processInstanceId != null) {
processService.abortProcessInstance(processInstanceId);
}
}
}
use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseWithAssessorInvolved.
@Test
public void testCarInsuranceClaimCaseWithAssessorInvolved() {
// 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();
// let's now add assessor to the case as we will need his/her opinion
caseService.assignToCaseRole(CAR_INS_CASE_ID, "assessor", new UserImpl("krisv"));
// 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();
// now krisv should have a task assigned as assessor
assertAndRunClaimAssessment();
// 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);
}
}
}
use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseWithNegotiations.
@Test
public void testCarInsuranceClaimCaseWithNegotiations() {
// 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 negotiate few times the calculated claim offer
assertAndNegotiateClaimOffer(3);
// 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);
}
}
}
Aggregations