use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleByRequest.
@Test
public void testChangeRoleByRequest() {
// Create role
IdmRoleDto changedRole = getHelper().createRole();
// Create request
IdmRequestDto request = requestManager.createRequest(changedRole);
Assert.assertNotNull(request);
Assert.assertEquals(request.getOwnerType(), changedRole.getClass().getName());
Assert.assertEquals(request.getOwnerId(), changedRole.getId());
// Change role (without save)
changedRole.setDescription(getHelper().createName());
changedRole.setPriority(1000);
// Create request item
Requestable requestable = requestManager.post(request.getId(), changedRole);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not same instance
Assert.assertTrue(changedRole != roleFromRequest);
// Has same values as new role
Assert.assertEquals(changedRole.getPriority(), roleFromRequest.getPriority());
Assert.assertEquals(changedRole.getDescription(), roleFromRequest.getDescription());
IdmRoleDto currentRole = roleService.get(changedRole.getId());
Assert.assertNotEquals(changedRole.getPriority(), currentRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), currentRole.getDescription());
// Start request
IdmRequestDto executedRequest = requestManager.executeRequest(request.getId());
Assert.assertNotNull(executedRequest);
Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
Assert.assertNotNull(executedRole);
// Has same values as new role
Assert.assertEquals(changedRole.getCode(), executedRole.getCode());
Assert.assertEquals(changedRole.getName(), executedRole.getName());
Assert.assertEquals(changedRole.getPriority(), executedRole.getPriority());
Assert.assertEquals(changedRole.getDescription(), executedRole.getDescription());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleWithGuaranteesDisapprov.
@Test
public void testChangeRoleWithGuaranteesDisapprov() {
// Create role with guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleDto changedRole = getHelper().createRole();
getHelper().createRoleGuarantee(changedRole, guarantee);
// Create request
IdmRequestDto request = requestManager.createRequest(changedRole);
Assert.assertNotNull(request);
Assert.assertEquals(request.getOwnerType(), changedRole.getClass().getName());
Assert.assertEquals(request.getOwnerId(), changedRole.getId());
// Change role (without save)
changedRole.setDescription(getHelper().createName());
changedRole.setPriority(1000);
// Create request item
Requestable requestable = requestManager.post(request.getId(), changedRole);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not same instance
Assert.assertTrue(changedRole != roleFromRequest);
// Has same values as new role
Assert.assertEquals(changedRole.getPriority(), roleFromRequest.getPriority());
Assert.assertEquals(changedRole.getDescription(), roleFromRequest.getDescription());
IdmRoleDto currentRole = roleService.get(changedRole.getId());
Assert.assertNotEquals(changedRole.getPriority(), currentRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), currentRole.getDescription());
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
loginAsNoAdmin(guarantee.getUsername());
try {
completeTasksFromUsers(guarantee.getId().toString(), "disapprove");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
// Reload the request (after disapproving)
executedRequest = requestService.get(executedRequest.getId());
Assert.assertEquals(RequestState.DISAPPROVED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
Assert.assertNotNull(executedRole);
// Has different values as new role
Assert.assertNotEquals(changedRole.getPriority(), executedRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), executedRole.getDescription());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleWithDirectGuaranteeType.
@Test
public void testChangeRoleWithDirectGuaranteeType() {
// Guarantee type -> set to null (default value).
getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
String guaranteeTypeOne = getHelper().createName();
String guaranteeTypeTwo = getHelper().createName();
// Create role with guarantee
IdmIdentityDto guaranteeOne = getHelper().createIdentity();
IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
IdmRoleDto changedRole = getHelper().createRole();
getHelper().createRoleGuarantee(changedRole, guaranteeOne, guaranteeTypeOne);
getHelper().createRoleGuarantee(changedRole, guaranteeTwo, guaranteeTypeTwo);
// Create request
IdmRequestDto request = createRequest(changedRole);
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
executedRequest = requestService.get(executedRequest.getId());
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
Assert.assertEquals(1, tasks.size());
WorkflowTaskInstanceDto workflowTaskInstanceDto = tasks.get(0);
List<IdentityLinkDto> candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
Assert.assertEquals(2, candidates.size());
Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
// Guarantee type -> set to guaranteeTypeOne.
getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeOne);
// Create request for guarantee type ONE.
request = createRequest(changedRole);
// Start request
executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
executedRequest = requestService.get(executedRequest.getId());
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
taskFilter = new WorkflowFilterDto();
taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
Assert.assertEquals(1, tasks.size());
workflowTaskInstanceDto = tasks.get(0);
candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
Assert.assertEquals(1, candidates.size());
Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
// Guarantee type -> set to guaranteeTypeTwo.
getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeTwo);
// Create request for guarantee type TWO.
request = createRequest(changedRole);
// Start request
executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
executedRequest = requestService.get(executedRequest.getId());
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
taskFilter = new WorkflowFilterDto();
requestService.get(executedRequest.getId());
taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
Assert.assertEquals(1, tasks.size());
workflowTaskInstanceDto = tasks.get(0);
candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
Assert.assertEquals(1, candidates.size());
Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
// Clear after test:
// Guarantee type -> set to null (default value).
getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testRoleWithEAV.
@Test
public void testRoleWithEAV() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Get definition
IdmFormInstanceDto formInstance = formService.getFormInstance(role);
// None values yet
Assert.assertEquals(0, formInstance.getValues().size());
IdmFormDefinitionDto formDefinition = formInstance.getFormDefinition();
// Create form attributes
IdmFormAttributeDto attributeShortText = new IdmFormAttributeDto();
attributeShortText.setCode(getHelper().createName());
attributeShortText.setName(attributeShortText.getCode());
attributeShortText.setPersistentType(PersistentType.SHORTTEXT);
attributeShortText.setFormDefinition(formDefinition.getId());
attributeShortText = formService.saveAttribute(attributeShortText);
IdmFormAttributeDto attributeBoolean = new IdmFormAttributeDto();
attributeBoolean.setCode(getHelper().createName());
attributeBoolean.setName(attributeBoolean.getCode());
attributeBoolean.setPersistentType(PersistentType.BOOLEAN);
attributeBoolean.setFormDefinition(formDefinition.getId());
attributeBoolean = formService.saveAttribute(attributeBoolean);
IdmFormAttributeDto attributeConfidential = new IdmFormAttributeDto();
attributeConfidential.setCode(getHelper().createName());
attributeConfidential.setName(attributeConfidential.getCode());
attributeConfidential.setPersistentType(PersistentType.SHORTTEXT);
attributeConfidential.setConfidential(true);
attributeConfidential.setFormDefinition(formDefinition.getId());
attributeConfidential = formService.saveAttribute(attributeConfidential);
IdmFormAttributeDto attributeInt = new IdmFormAttributeDto();
attributeInt.setCode(getHelper().createName());
attributeInt.setName(attributeInt.getCode());
attributeInt.setPersistentType(PersistentType.INT);
attributeInt.setFormDefinition(formDefinition.getId());
attributeInt = formService.saveAttribute(attributeInt);
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
IdmFormInstanceDto formInstanceRequest = requestManager.getFormInstance(request.getId(), role, formDefinition);
// None values yet
Assert.assertEquals(0, formInstanceRequest.getValues().size());
IdmFormValueDto valueShortText = new IdmFormValueDto(attributeShortText);
valueShortText.setValue(getHelper().createName());
formInstanceRequest.getValues().add(valueShortText);
IdmFormValueDto valueBoolean = new IdmFormValueDto(attributeBoolean);
valueBoolean.setValue(true);
formInstanceRequest.getValues().add(valueBoolean);
IdmFormValueDto valueConfidential = new IdmFormValueDto(attributeConfidential);
String confidentialValueString = getHelper().createName();
valueConfidential.setValue(confidentialValueString);
formInstanceRequest.getValues().add(valueConfidential);
IdmFormValueDto valueInt = new IdmFormValueDto(attributeInt);
valueInt.setValue(111);
formInstanceRequest.getValues().add(valueInt);
formDefinition = formService.getDefinition(IdmRoleDto.class);
requestManager.saveFormInstance(request.getId(), role, formDefinition, formInstanceRequest.getValues());
formInstanceRequest = requestManager.getFormInstance(request.getId(), role, formDefinition);
// Four values in request
Assert.assertEquals(4, formInstanceRequest.getValues().size());
formInstance = formService.getFormInstance(role);
// None values via standard service
Assert.assertEquals(0, formInstance.getValues().size());
long numberOfNewValue = formInstanceRequest.getValues().stream().filter(value -> RequestOperationType.ADD == DtoUtils.getEmbedded(value, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class).getOperation()).count();
Assert.assertEquals(4, numberOfNewValue);
// Check confidential value in request
IdmFormValueDto confidentialValueDto = formInstanceRequest.getValues().stream().filter(value -> valueConfidential.getFormAttribute().equals(value.getFormAttribute())).findFirst().get();
// Cannot be same, because this value is confidential
Assert.assertNotEquals(confidentialValueString, confidentialValueDto.getValue());
request = requestManager.startRequest(request.getId(), true);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
formInstance = formService.getFormInstance(role);
// Four values via standard service
Assert.assertEquals(4, formInstance.getValues().size());
// Check short text
long countShortText = formInstance.getValues().stream().filter(value -> valueShortText.getFormAttribute().equals(value.getFormAttribute())).filter(value -> valueShortText.getValue().equals(value.getValue())).count();
Assert.assertEquals(1, countShortText);
// Check int
long countInt = formInstance.getValues().stream().filter(value -> valueInt.getFormAttribute().equals(value.getFormAttribute())).filter(value -> valueInt.getValue().equals(value.getValue())).count();
Assert.assertEquals(1, countInt);
// Check boolean
long countBoolean = formInstance.getValues().stream().filter(value -> valueBoolean.getFormAttribute().equals(value.getFormAttribute())).filter(value -> valueBoolean.getValue().equals(value.getValue())).count();
Assert.assertEquals(1, countBoolean);
// Check confidential
IdmFormValueDto confidentialValue = formInstance.getValues().stream().filter(value -> valueConfidential.getFormAttribute().equals(value.getFormAttribute())).findFirst().get();
// Cannot be same, because this value is confidential
Assert.assertNotEquals(confidentialValueString, confidentialValue.getValue());
Serializable confidValue = formService.getConfidentialPersistentValue(confidentialValue);
Assert.assertEquals(confidentialValueString, confidValue);
// Delete attributes
formService.deleteValues(role, attributeShortText);
formService.deleteAttribute(attributeShortText);
formService.deleteValues(role, attributeBoolean);
formService.deleteAttribute(attributeBoolean);
formService.deleteValues(role, attributeConfidential);
formService.deleteAttribute(attributeConfidential);
formService.deleteValues(role, attributeInt);
formService.deleteAttribute(attributeInt);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testFind.
@Test
public void testFind() {
// Create role
IdmRoleDto role = getHelper().createRole();
// Create guarantee One
IdmIdentityDto guaranteeOne = getHelper().createIdentity();
IdmRoleGuaranteeDto roleGuaranteeOne = getHelper().createRoleGuarantee(role, guaranteeOne);
IdmRoleGuaranteeFilter guaranteeFilter = new IdmRoleGuaranteeFilter();
guaranteeFilter.setRole(role.getId());
Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
// Create request
IdmRequestDto request = requestManager.createRequest(role);
Assert.assertNotNull(request);
List<IdmRoleGuaranteeDto> guarantees = requestManager.find(IdmRoleGuaranteeDto.class, request.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guarantees.size());
// Create guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleGuaranteeDto roleGuaranteeTwo = new IdmRoleGuaranteeDto();
roleGuaranteeTwo.setRole(role.getId());
roleGuaranteeTwo.setGuarantee(guarantee.getId());
IdmRoleGuaranteeDto requestablePost = requestManager.post(request.getId(), roleGuaranteeTwo);
IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded(requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
// Find via standard service returns still only one result
Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
// Find via request manager returns two results
guarantees = requestManager.find(IdmRoleGuaranteeDto.class, request.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(2, guarantees.size());
// Create new request
IdmRequestDto requestTwo = requestManager.createRequest(role);
Assert.assertNotNull(requestTwo);
guarantees = requestManager.find(IdmRoleGuaranteeDto.class, requestTwo.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guarantees.size());
// Change the role-guarantee (use new guarantee)
IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
roleGuaranteeOne.setGuarantee(guaranteeTwo.getId());
IdmRoleGuaranteeDto roleGuaranteeOneRequest = requestManager.post(requestTwo.getId(), roleGuaranteeOne);
changeRequestItem = DtoUtils.getEmbedded(roleGuaranteeOneRequest, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
// Role guarantee One are equals (same ID), but must have different guarantee
IdmRoleGuaranteeDto currentRoleGuaranteeOne = roleGuaranteeService.get(roleGuaranteeOne);
Assert.assertEquals(currentRoleGuaranteeOne, roleGuaranteeOneRequest);
Assert.assertNotEquals(currentRoleGuaranteeOne.getGuarantee(), roleGuaranteeOneRequest.getGuarantee());
guarantees = roleGuaranteeService.find(guaranteeFilter, null).getContent();
// Find via standard service returns still only one result
Assert.assertEquals(1, guarantees.size());
// Find via request manager returns one result too (item was only updated in the
// request)
List<IdmRoleGuaranteeDto> guaranteesRequest = requestManager.find(IdmRoleGuaranteeDto.class, requestTwo.getId(), guaranteeFilter, null).getContent();
Assert.assertEquals(1, guaranteesRequest.size());
// Role guarantee One are equals (same ID), but must have different guarantee
Assert.assertEquals(guarantees.get(0), guaranteesRequest.get(0));
Assert.assertNotEquals(guarantees.get(0).getGuarantee(), guaranteesRequest.get(0).getGuarantee());
}
Aggregations