use of org.jbpm.services.task.impl.model.GroupImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseAuthorization.
@Test
public void testCaseAuthorization() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("contact", new GroupImpl("HR"));
Map<String, Object> data = new HashMap<>();
data.put("s", "description");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(HR_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
identityProvider.setName("mary");
try {
caseService.cancelCase(caseId);
fail("Mary is not owner of the case so should not be allowed to cancel the case");
} catch (SecurityException e) {
// expected
}
try {
caseService.destroyCase(caseId);
fail("Mary is not owner of the case so should not be allowed to destroy the case");
} catch (SecurityException e) {
// expected
}
identityProvider.setName("john");
caseService.cancelCase(caseId);
identityProvider.setName("mary");
try {
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
fail("Mary is not owner of the case so should not be allowed to reopen the case");
} catch (SecurityException e) {
// expected
}
identityProvider.setName("john");
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(HR_CASE_ID, cInstance.getCaseId());
} 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.services.task.impl.model.GroupImpl 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");
}
use of org.jbpm.services.task.impl.model.GroupImpl in project jbpm by kiegroup.
the class CaseAssignmentServiceImplTest method testRoleAssignedMissingUserAutoStart.
@Test
public void testRoleAssignedMissingUserAutoStart() {
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).assignUser("generalRole", "john");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
caseService.startCase(deploymentUnit.getIdentifier(), CASE_X_P_ID, caseFile);
}).withMessageContaining("Case role 'generalRole' has no matching assignments");
}
use of org.jbpm.services.task.impl.model.GroupImpl 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);
}
}
}
use of org.jbpm.services.task.impl.model.GroupImpl 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);
}
}
}
Aggregations