use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithIndependentDynamicSubCaseAbortMainCase.
@Test
public void testStartCaseWithIndependentDynamicSubCaseAbortMainCase() {
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> parameters = new HashMap<>();
parameters.put("CaseDefinitionId", "UserTaskCase");
parameters.put("DeploymentId", deploymentUnit.getIdentifier());
parameters.put("UserRole_owner", "john");
parameters.put("Data_s", "#{name}");
parameters.put("Independent", "true");
TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
caseService.addDynamicTask(caseId, taskSpecification);
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(FIRST_CASE_ID));
assertTrue(byCaseId.containsKey(HR_CASE_ID));
caseService.cancelCase(caseId);
caseId = HR_CASE_ID;
caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(1, caseInstances.size());
caseInstances = caseRuntimeDataService.getCaseInstances(Arrays.asList(CaseStatus.CANCELLED), new QueryContext());
assertNotNull(caseInstances);
assertEquals(1, caseInstances.size());
} 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.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseCloseCaseFromRules.
@Test
public void testCarInsuranceClaimCaseCloseCaseFromRules() {
// 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 close case as part of rules evaluation
caseService.addDataToCaseFile(CAR_INS_CASE_ID, "CaseAction", "Close");
// 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);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method assertCaseInstance.
protected void assertCaseInstance(String deploymentId, String caseId) {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(caseId, cInstance.getCaseId());
assertEquals(deploymentId, cInstance.getDeploymentId());
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseCloseCaseFromAsyncCommand.
@Test(timeout = 20000)
public void testCarInsuranceClaimCaseCloseCaseFromAsyncCommand() {
executorService = ExecutorServiceFactory.newExecutorService(emf);
executorService.init();
CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
// 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("CaseId", CAR_INS_CASE_ID);
parameters.put("CommandClass", AsyncCloseCaseCommand.class.getName());
caseService.addDynamicTask(CAR_INS_CASE_ID, caseService.newTaskSpec("async", "CloseCaseAsync", parameters));
countDownListener.waitTillCompleted();
// 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 async command", 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);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseAssignmentServiceImplTest method testProperRoleAssignedAutoStart.
@Test
public void testProperRoleAssignedAutoStart() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("actorRole", new UserImpl("john"));
roleAssignments.put("groupRole", new GroupImpl("managers"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), CASE_X_P_ID, data, roleAssignments);
((CaseAssignment) caseFile).assignGroup("generalRole", "managers");
((CaseAssignment) caseFile).assignUser("generalRole", "john");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), CASE_X_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());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations