use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithStageAutoStartNodes.
@Test
public void testCaseWithStageAutoStartNodes() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
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());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
assertTask(tasks.get(0), "john", "Ask for input", Status.Reserved);
assertTask(tasks.get(1), "john", "Missing data", Status.Reserved);
} 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.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithDefinedDataRestrictionsSetViaUserTask.
@Test
public void testCaseWithDefinedDataRestrictionsSetViaUserTask() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("participant", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("contactInfo", "main street 10, NYC");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(1, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
Map<String, Object> params = new HashMap<>();
params.put("reply_", "John sets the reply via process");
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(1, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
identityProvider.setName("mary");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(1, caseData.size());
assertEquals("John sets the reply via process", caseData.get("reply"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
identityProvider.setName("john");
caseService.cancelCase(caseId);
}
}
}
use of org.kie.api.task.model.OrganizationalEntity 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.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method startAndAssertCaseInstance.
protected String startAndAssertCaseInstance(String deploymentId, String insured, String insuranceRepresentative) {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("insured", new UserImpl(insured));
roleAssignments.put("insuranceRepresentative", new UserImpl(insuranceRepresentative));
roleAssignments.put("assessor", new UserImpl("krisv"));
// start new instance of a case with data and role assignment
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentId, CAR_INSURANCE_CLAIM_PROC_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentId, CAR_INSURANCE_CLAIM_PROC_ID, caseFile);
assertNotNull(caseId);
assertEquals(CAR_INS_CASE_ID, caseId);
return caseId;
}
use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseAssignmentServiceImplTest method testRoleAssignedMissingGroupAutoStart.
@Test
public void testRoleAssignedMissingGroupAutoStart() {
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");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
caseService.startCase(deploymentUnit.getIdentifier(), CASE_X_P_ID, caseFile);
}).withMessageContaining("Case role 'generalRole' has no matching assignments");
}
Aggregations