Search in sources :

Example 6 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testGetChangesOnCreateRoleByRequest.

@Test
public void testGetChangesOnCreateRoleByRequest() {
    IdmRoleDto newRole = new IdmRoleDto();
    newRole.setCode(getHelper().createName());
    newRole.setName(newRole.getCode());
    newRole.setPriority(10);
    newRole.setDescription(getHelper().createName());
    IdmRequestDto request = requestManager.createRequest(newRole);
    Assert.assertNotNull(request);
    Requestable requestable = requestManager.post(request.getId(), newRole);
    Assert.assertNotNull(requestable);
    IdmRequestItemChangesDto changes = requestManager.getChanges(requestItemService.get(requestable.getRequestItem()));
    Assert.assertNotNull(changes);
    List<IdmRequestItemAttributeDto> attributes = changes.getAttributes();
    attributes.forEach(attribute -> {
        Assert.assertEquals(RequestOperationType.ADD, attribute.getValue().getChange());
    });
}
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) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 7 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class IdmRequestFilterTest method ownerTest.

@Test
public void ownerTest() {
    String ownerType = IdmIdentityDto.class.toString();
    IdmRequestDto request1 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestDto request2 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestDto request3 = createRequest(ownerType, UUID.randomUUID());
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(request1.getOwnerId());
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request1.getName(), content.get(0).getName());
    filter.setOwnerId(request2.getOwnerId());
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request2.getName(), content.get(0).getName());
    filter.setOwnerId(request3.getOwnerId());
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    Assert.assertEquals(request3.getName(), content.get(0).getName());
}
Also used : IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 8 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class IdmRequestFilterTest method stateTest.

@Test
public void stateTest() {
    UUID ownerId = UUID.randomUUID();
    String ownerType = IdmIdentityDto.class.toString();
    List<RequestState> states = new ArrayList<>();
    RequestState state = RequestState.APPROVED;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(ownerId);
    filter.setStates(states);
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(3, content.size());
    state = RequestState.CANCELED;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(6, content.size());
    state = RequestState.EXCEPTION;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(9, content.size());
    state = RequestState.IN_PROGRESS;
    states.add(state);
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    changeState(state, createRequest(ownerType, ownerId));
    filter.setStates(states);
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(12, content.size());
}
Also used : RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) ArrayList(java.util.ArrayList) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 9 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testDeleteRequestable.

@Test
public void testDeleteRequestable() {
    // 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());
    Assert.assertNotNull(requestItemService.get(requestable.getRequestItem()));
    // Delete the role
    roleService.delete(changedRole);
    // Request item must be canceled
    IdmRequestItemDto requestItem = requestItemService.get(requestable.getRequestItem());
    Assert.assertNotNull(requestItem);
    Assert.assertEquals(RequestState.CANCELED, requestItem.getState());
    // Request must be canceled
    request = requestService.get(request.getId());
    Assert.assertNotNull(request);
    Assert.assertEquals(RequestState.CANCELED, request.getState());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) 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 10 with IdmRequestDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testChangeRoleWithGuaranteesApprove.

@Test
public void testChangeRoleWithGuaranteesApprove() {
    // 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(), "approve");
    } 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 approving)
    executedRequest = requestService.get(executedRequest.getId());
    Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
    IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
    // Role must exists now
    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) 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)

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