Search in sources :

Example 36 with IdmRequestDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 37 with IdmRequestDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 38 with IdmRequestDto

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);
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Assert.fail(org.junit.Assert.fail) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Before(org.junit.Before) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRoleGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) Test(org.junit.Test) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) Assert(org.junit.Assert) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 39 with IdmRequestDto

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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Assert.fail(org.junit.Assert.fail) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Before(org.junit.Before) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRoleGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) Test(org.junit.Test) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) Assert(org.junit.Assert) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 40 with IdmRequestDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Aggregations

IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)47 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)25 Test (org.junit.Test)24 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)23 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)23 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)18 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)18 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)11 UUID (java.util.UUID)11 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)9 Transactional (org.springframework.transaction.annotation.Transactional)9 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)8 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)8 IdmRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter)8 IdmRequestService (eu.bcvsolutions.idm.core.api.service.IdmRequestService)8 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)8 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)8 Lists (com.google.common.collect.Lists)7 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)7