use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesByIdentityWithValid.
@Test
@Transactional
public void testCopyRolesByIdentityWithValid() {
LocalDate validFrom = LocalDate.now().minusDays(5);
LocalDate validTill = LocalDate.now().plusDays(55);
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
IdmIdentityContractDto primeContract = this.getHelper().getPrimeContract(identityDto);
this.getHelper().createIdentityRole(primeContract, roleOne);
this.getHelper().createIdentityRole(primeContract, roleTwo);
IdmIdentityDto newIdentity = this.getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto newIdentityContract = this.getHelper().getPrimeContract(newIdentity);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identityDto.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(newIdentityContract);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(newIdentityContract.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setValidFrom(validFrom);
requestByIdentityDto.setValidTill(validTill);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
assertNotNull(copyRolesByIdentity);
assertEquals(createdRequest.getId(), copyRolesByIdentity.getId());
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOne.getId());
}).findAny().orElse(null);
assertNotNull(conceptOne);
assertEquals(validFrom, conceptOne.getValidFrom());
assertEquals(validTill, conceptOne.getValidTill());
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
assertEquals(validFrom, conceptTwo.getValidFrom());
assertEquals(validTill, conceptTwo.getValidTill());
}
Aggregations