Search in sources :

Example 31 with IdmRequestDto

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

the class IdmRequestFilterTest method dateTest.

@Test
public void dateTest() {
    UUID ownerId = UUID.randomUUID();
    String ownerType = IdmIdentityDto.class.toString();
    IdmRequestDto createRequest = createRequest(ownerType, ownerId);
    ZonedDateTime createdDate = createRequest.getCreated();
    // 
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setCreatedAfter(createdDate.minusSeconds(10));
    filter.setCreatedBefore(createdDate.plusSeconds(10));
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(1, content.size());
    // 
    filter.setCreatedAfter(createdDate.minusSeconds(10));
    filter.setCreatedBefore(createdDate.minusSeconds(9));
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(0, content.size());
    // 
    filter.setCreatedAfter(createdDate.plusSeconds(10));
    filter.setCreatedBefore(createdDate.plusSeconds(11));
    content = requestService.find(filter, null).getContent();
    Assert.assertEquals(0, content.size());
}
Also used : IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) ZonedDateTime(java.time.ZonedDateTime) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 32 with IdmRequestDto

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

the class IdmRequestFilterTest method createRequest.

/**
 * Method creates IdmRequestDto
 * @param ownerType
 * @param ownerId
 * @return
 */
private IdmRequestDto createRequest(String ownerType, UUID ownerId) {
    IdmRequestDto request = new IdmRequestDto();
    request.setName("request" + System.currentTimeMillis());
    request.setOwnerType(ownerType);
    request.setRequestType("Request");
    request.setOwnerId(ownerId);
    return requestService.save(request);
}
Also used : IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)

Example 33 with IdmRequestDto

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

the class IdmRequestFilterTest method ownerTypeTest.

@Test
public void ownerTypeTest() {
    UUID ownerId = UUID.randomUUID();
    String ownerType = IdmRoleDto.class.toString();
    createRequest(ownerType, ownerId);
    createRequest(ownerType, ownerId);
    createRequest(ownerType, ownerId);
    createRequest(IdmIdentityDto.class.toString(), ownerId);
    IdmRequestFilter filter = new IdmRequestFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(ownerId);
    List<IdmRequestDto> content = requestService.find(filter, null).getContent();
    Assert.assertEquals(3, content.size());
}
Also used : IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 34 with IdmRequestDto

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

the class RequestManagerTest method testDeleteRequestIntegrityWithWf.

@Test
public void testDeleteRequestIntegrityWithWf() {
    // Log as admin, but not user 'admin' (we don't want to skip WF)
    IdmIdentityDto adminUser = getHelper().createIdentity();
    loginAsAdmin(adminUser.getUsername());
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    // Create guarantee
    IdmIdentityDto guarantee = getHelper().createIdentity();
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(guarantee.getId());
    Requestable requestablePost = requestManager.post(request.getId(), roleGuarantee);
    IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.ADD, changeRequestItem.getOperation());
    Assert.assertTrue(requestablePost instanceof IdmRoleGuaranteeDto);
    // Change role (without save)
    role.setDescription(getHelper().createName());
    role.setPriority(1000);
    // Create request item
    Requestable requestable = requestManager.post(request.getId(), role);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    executedRequest = requestService.get(executedRequest.getId());
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    String processId = executedRequest.getWfProcessId();
    Assert.assertNotNull(processId);
    // Wf process is in progress
    WorkflowProcessInstanceDto processInstace = workflowProcessInstanceService.get(processId);
    Assert.assertNotNull(processInstace);
    // Two items should be created
    Assert.assertEquals(2, requestManager.findRequestItems(request.getId(), null).size());
    // Delete the request
    requestService.delete(executedRequest);
    IdmRequestDto requestDeleted = requestService.get(executedRequest.getId());
    Assert.assertNull(requestDeleted);
    // Process should be deleted (canceled)
    processInstace = workflowProcessInstanceService.get(processId);
    Assert.assertNull(processInstace);
}
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) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 35 with IdmRequestDto

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

the class RequestManagerTest method testBasicItemIntegrity.

@Test
public void testBasicItemIntegrity() {
    // Create role
    IdmRoleDto role = getHelper().createRole();
    // Create request
    IdmRequestDto request = requestManager.createRequest(role);
    Assert.assertNotNull(request);
    // null -> DELETE
    // Create delete request item
    Requestable requestable = requestManager.delete(request.getId(), role);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    IdmRequestItemDto requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
    Assert.assertTrue(requestable instanceof IdmRoleDto);
    // DELETE -> CHANGE
    // Create change request item
    role.setDescription(getHelper().createName());
    Requestable requestablePost = requestManager.post(request.getId(), requestable);
    IdmRequestItemDto changeRequestItem = DtoUtils.getEmbedded((AbstractDto) requestablePost, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.UPDATE, changeRequestItem.getOperation());
    // In one request can exists only one item for same owner -> change item must be
    // same (updated) as in delete cause.
    Assert.assertEquals(requestItem.getId(), changeRequestItem.getId());
    // CHANGE -> null
    // Create delete request item (again)
    requestable = requestManager.delete(request.getId(), requestablePost);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    // Previous item was deleted
    List<IdmRequestItemDto> items = requestManager.findRequestItems(request.getId(), null);
    Assert.assertEquals(0, items.size());
    // null -> DELETE
    // Create delete request item
    requestable = requestManager.delete(request.getId(), requestable);
    Assert.assertNotNull(requestable);
    Assert.assertNotNull(requestable.getRequestItem());
    requestItem = DtoUtils.getEmbedded((AbstractDto) requestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.REMOVE, requestItem.getOperation());
    // DELETE -> null
    // Again delete same DTO. In this situation should be previous item (delete)
    // deleted.
    requestable = requestManager.delete(request.getId(), requestable);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
    IdmRoleDto newRole = new IdmRoleDto();
    newRole.setCode(getHelper().createName());
    newRole.setName(newRole.getCode());
    // null -> ADD
    Requestable newRequestable = requestManager.post(request.getId(), newRole);
    Assert.assertNotNull(newRequestable);
    Assert.assertNotNull(newRequestable.getRequestItem());
    IdmRequestItemDto newRequestItem = DtoUtils.getEmbedded((AbstractDto) newRequestable, Requestable.REQUEST_ITEM_FIELD, IdmRequestItemDto.class);
    Assert.assertEquals(RequestOperationType.ADD, newRequestItem.getOperation());
    // One item must exists now
    Assert.assertEquals(1, requestManager.findRequestItems(request.getId(), null).size());
    // ADD -> null
    // Delete of DTO, which is not created in DB causes his deleting.
    requestable = requestManager.delete(request.getId(), newRequestable);
    Assert.assertNotNull(requestable);
    Assert.assertNull(requestable.getRequestItem());
    Assert.assertEquals(0, requestManager.findRequestItems(request.getId(), null).size());
}
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) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) 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