use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindValidRoles.
@Test
public void testFindValidRoles() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
// valid
IdmIdentityRoleDto validRole = getHelper().createIdentityRole(identity, getHelper().createRole());
// inValidByDate
getHelper().createIdentityRole(identity, getHelper().createRole(), null, LocalDate.now().minusDays(2));
IdmIdentityContractDto invalidContract = getHelper().createContract(identity, null, null, LocalDate.now().minusDays(2));
// inValidByContract
getHelper().createIdentityRole(invalidContract, getHelper().createRole());
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
filter.setValid(Boolean.TRUE);
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(validRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method prepareDto.
@Override
protected IdmIdentityRoleDto prepareDto() {
IdmIdentityRoleDto dto = new IdmIdentityRoleDto();
dto.setIdentityContractDto(getHelper().getPrimeContract(getHelper().createIdentity().getId()));
dto.setRole(getHelper().createRole().getId());
dto.setValidFrom(LocalDate.now());
dto.setValidTill(LocalDate.now().plusDays(1));
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindByRoleEnvironment.
@Test
public void testFindByRoleEnvironment() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto roleOne = getHelper().createRole(null, getHelper().createName(), getHelper().createName());
IdmRoleDto roleTwo = getHelper().createRole(null, getHelper().createName(), getHelper().createName());
IdmIdentityRoleDto createIdentityRole = getHelper().createIdentityRole(identity, roleOne);
getHelper().createIdentityRole(identity, roleTwo);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleEnvironment(roleOne.getEnvironment());
List<IdmIdentityRoleDto> results = find(filter);
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(createIdentityRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindAutomaticRoles.
@Test
public void testFindAutomaticRoles() {
IdmIdentityContractDto contract = getHelper().getPrimeContract(getHelper().createIdentity().getId());
// normal
IdmIdentityRoleDto normal = getHelper().createIdentityRole(contract, getHelper().createRole());
// automatic
IdmIdentityRoleDto automaticIdentityRole = new IdmIdentityRoleDto();
automaticIdentityRole.setIdentityContract(contract.getId());
IdmRoleDto role = getHelper().createRole();
automaticIdentityRole.setRole(role.getId());
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
automaticIdentityRole.setAutomaticRole(automaticRole.getId());
IdmIdentityRoleDto automatic = createDto(automaticIdentityRole);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
filter.setAutomaticRole(Boolean.TRUE);
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(automatic.getId())));
//
filter.setAutomaticRole(Boolean.FALSE);
results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(normal.getId())));
//
// find by automatic role
filter.setAutomaticRole(null);
filter.setAutomaticRoleId(automaticRole.getId());
results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getId().equals(automatic.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testExecuteRoleRequestValue.
@Test
public void testExecuteRoleRequestValue() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto role = createRoleWithAttributes();
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmFormDefinitionDto definition = formService.getDefinition(role.getIdentityRoleAttributeDefinition());
IdmFormAttributeDto ipAttributeDto = //
definition.getFormAttributes().stream().filter(//
attribute -> IP.equals(attribute.getCode())).findFirst().get();
// Add value
IdmFormValueDto formValue = new IdmFormValueDto(ipAttributeDto);
formValue.setStringValue(getHelper().createName());
formValue.setPersistentType(PersistentType.TEXT);
formValue.setFormAttribute(ipAttributeDto.getId());
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(definition);
formInstance.getValues().add(formValue);
// Create request
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setExecuteImmediately(true);
request = roleRequestService.save(request);
// Create concept
IdmConceptRoleRequestDto conceptRole = new IdmConceptRoleRequestDto();
conceptRole.setIdentityContract(identityContact.getId());
conceptRole.setRole(role.getId());
conceptRole.setOperation(ConceptRoleRequestOperation.ADD);
conceptRole.setRoleRequest(request.getId());
conceptRole.getEavs().add(formInstance);
conceptRole = conceptRoleService.save(conceptRole);
IdmRoleRequestDto roleRequestDto = getHelper().startRequestInternal(request, false, true);
assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
conceptRole = conceptRoleService.get(conceptRole.getId());
assertEquals(RoleRequestState.EXECUTED, conceptRole.getState());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(identityContact.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRoleDto);
assertNotNull(formInstanceDto);
List<IdmFormValueDto> values = formInstanceDto.getValues();
assertEquals(1, values.size());
assertEquals(formValue.getValue(), values.get(0).getValue());
}
Aggregations