Search in sources :

Example 11 with IdmIncompatibleRoleDto

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);
}
Also used : IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto)

Example 12 with IdmIncompatibleRoleDto

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());
}
Also used : List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmIncompatibleRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIncompatibleRoleFilter) Test(org.junit.Test) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIncompatibleRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIncompatibleRoleFilter) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 13 with IdmIncompatibleRoleDto

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;
}
Also used : IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto)

Example 14 with IdmIncompatibleRoleDto

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());
    }));
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 15 with IdmIncompatibleRoleDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Aggregations

IdmIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto)21 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 Test (org.junit.Test)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 List (java.util.List)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 ResolvedIncompatibleRoleDto (eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto)10 Assert (org.junit.Assert)10 Set (java.util.Set)9 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)7 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)7 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 Collectors (java.util.stream.Collectors)7 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)6 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)6 Lists (com.google.common.collect.Lists)5 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)4