use of eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createIncompatibleRole.
@Override
public IdmIncompatibleRoleDto createIncompatibleRole(IdmRoleDto superior, IdmRoleDto sub) {
IdmIncompatibleRoleDto IncompatibleRole = new IdmIncompatibleRoleDto();
IncompatibleRole.setSuperior(superior.getId());
IncompatibleRole.setSub(sub.getId());
//
return incompatibleRoleService.save(IncompatibleRole);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIncompatibleRoleControllerRestTest method testFindBySuperior.
@Test
public void testFindBySuperior() {
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmRoleDto roleThree = getHelper().createRole();
//
IdmIncompatibleRoleDto incompatibleRoleOne = getHelper().createIncompatibleRole(roleOne, roleTwo);
IdmIncompatibleRoleDto incompatibleRoleTwo = getHelper().createIncompatibleRole(roleThree, roleOne);
IdmIncompatibleRoleDto incompatibleRoleThree = getHelper().createIncompatibleRole(roleThree, roleTwo);
//
IdmIncompatibleRoleFilter filter = new IdmIncompatibleRoleFilter();
filter.setSuperiorId(roleOne.getId());
List<IdmIncompatibleRoleDto> incompatibleRoles = find(filter);
Assert.assertEquals(1, incompatibleRoles.size());
Assert.assertEquals(incompatibleRoleOne.getId(), incompatibleRoles.get(0).getId());
//
filter.setSuperiorId(roleThree.getId());
incompatibleRoles = find(filter);
Assert.assertEquals(2, incompatibleRoles.size());
Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> ir.getId().equals(incompatibleRoleTwo.getId())));
Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> ir.getId().equals(incompatibleRoleThree.getId())));
//
filter.setSuperiorId(roleTwo.getId());
incompatibleRoles = find(filter);
Assert.assertTrue(incompatibleRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIncompatibleRoleControllerRestTest method prepareDto.
@Override
protected IdmIncompatibleRoleDto prepareDto() {
IdmIncompatibleRoleDto dto = new IdmIncompatibleRoleDto();
dto.setSuperior(getHelper().createRole().getId());
dto.setSub(getHelper().createRole().getId());
//
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRoleRequestControllerRestTest method testGetIncompatibleRoles.
@Test
public void testGetIncompatibleRoles() throws Exception {
IdmRoleRequestDto roleRequest = createDto();
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmRoleDto roleThree = getHelper().createRole();
IdmRoleDto roleFour = getHelper().createRole();
IdmRoleDto roleFive = getHelper().createRole();
IdmRoleDto roleSix = getHelper().createRole();
// assign roles
IdmIdentityDto applicant = identityService.get(roleRequest.getApplicant());
getHelper().createIdentityRole(applicant, roleOne);
getHelper().createIdentityRole(applicant, roleTwo);
getHelper().createIdentityRole(applicant, roleThree);
// create incompatible roles definition
getHelper().createIncompatibleRole(roleOne, roleTwo);
getHelper().createIncompatibleRole(roleThree, roleFour);
getHelper().createIncompatibleRole(roleOne, roleSix);
//
// create concepts
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(roleRequest.getId());
concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
concept.setRole(roleFour.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
conceptRoleRequestService.save(concept);
concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(roleRequest.getId());
concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
concept.setRole(roleFive.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
conceptRoleRequestService.save(concept);
//
String response = getMockMvc().perform(get(String.format("%s/incompatible-roles", getDetailUrl(roleRequest.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
//
Set<IdmIncompatibleRoleDto> incompatibleRoles = toDtos(response, ResolvedIncompatibleRoleDto.class).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
Assert.assertEquals(1, incompatibleRoles.size());
Assert.assertTrue(incompatibleRoles.stream().anyMatch(ir -> {
return ir.getSuperior().equals(roleThree.getId()) && ir.getSub().equals(roleFour.getId());
}));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRoleRequestControllerRestTest method testGetIncompatibleRolesWithoutRemovedInConcept.
@Test
public void testGetIncompatibleRolesWithoutRemovedInConcept() throws Exception {
IdmRoleRequestDto roleRequest = createDto();
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmRoleDto roleThree = getHelper().createRole();
IdmRoleDto roleFour = getHelper().createRole();
IdmRoleDto roleFive = getHelper().createRole();
IdmRoleDto roleSix = getHelper().createRole();
// assign roles
IdmIdentityDto applicant = identityService.get(roleRequest.getApplicant());
getHelper().createIdentityRole(applicant, roleOne);
getHelper().createIdentityRole(applicant, roleTwo);
IdmIdentityRoleDto identityRole = getHelper().createIdentityRole(applicant, roleThree);
getHelper().createIdentityRole(applicant, roleFour);
// create incompatible roles definition
getHelper().createIncompatibleRole(roleOne, roleTwo);
getHelper().createIncompatibleRole(roleThree, roleFour);
getHelper().createIncompatibleRole(roleOne, roleSix);
//
// create concepts
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(roleRequest.getId());
concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
concept.setRole(roleFour.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequestService.save(concept);
concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(roleRequest.getId());
concept.setIdentityContract(getHelper().getPrimeContract(applicant).getId());
concept.setRole(roleFive.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
conceptRoleRequestService.save(concept);
//
String response = getMockMvc().perform(get(String.format("%s/incompatible-roles", getDetailUrl(roleRequest.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
//
Set<IdmIncompatibleRoleDto> incompatibleRoles = toDtos(response, ResolvedIncompatibleRoleDto.class).stream().map(ResolvedIncompatibleRoleDto::getIncompatibleRole).collect(Collectors.toSet());
Assert.assertEquals(0, incompatibleRoles.size());
}
Aggregations