Search in sources :

Example 31 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class VsRequestRealizeBulkActionTest method testRealizeRequest.

@Test
public void testRealizeRequest() {
    IdmIdentityDto implementer = helper.createIdentity();
    IdmIdentityDto identity = helper.createIdentity();
    IdmRoleDto roleForVs = helper.createRole();
    SysSystemDto system = this.createVirtualSystem(implementer, null);
    helper.createRoleSystem(roleForVs, system);
    helper.createIdentityRole(identity, roleForVs);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(identity.getUsername());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(identity.getUsername(), request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(identity.getUsername(), system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try cancel the request
    IdmBulkActionDto bulkAction = this.findBulkAction(VsRequest.class, VsRequestRealizeBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(request.getId()));
    String reason = helper.createName();
    Map<String, Object> properties = new HashMap<>();
    properties.put(VsRequestRealizeBulkAction.REASON, reason);
    bulkAction.setProperties(properties);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1L, null, null);
    request = requestService.get(request.getId());
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    Assert.assertEquals(reason, request.getReason());
    account = accountService.findByUidSystem(identity.getUsername(), system.getId());
    Assert.assertNotNull(account);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 32 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class VsRequestControllerRestTest method checkGetMethodMissingRequest.

@Test
public void checkGetMethodMissingRequest() throws Exception {
    SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
    IdmRoleDto roleOne = helper.createRole(helper.createName());
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    // Assign system to role
    helper.createRoleSystem(roleOne, virtualSystem);
    helper.assignRoles(helper.getPrimeContract(identity.getId()), false, roleOne);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(virtualSystem.getId());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto vsRequestDto = requests.get(0);
    vsRequestDto.setRoleRequestId(UUID.randomUUID());
    vsRequestDto = requestService.save(vsRequestDto);
    String url = String.format("%s%s/%s", BaseDtoController.BASE_PATH, "/vs/requests", vsRequestDto.getId());
    ResultActions andExpect = getMockMvc().perform(get(url).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(jsonPath("$.id", equalTo(vsRequestDto.getId().toString())));
    assertNotNull(andExpect);
    String contentAsString = andExpect.andReturn().getResponse().getContentAsString();
    JSONObject tObject = new JSONObject(contentAsString);
    String embeddedString = tObject.get(EmbeddedDto.PROPERTY_EMBEDDED).toString();
    tObject = new JSONObject(embeddedString);
    try {
        tObject.get(IdmConceptRoleRequestService.ROLE_REQUEST_FIELD).toString();
        fail();
    } catch (JSONException e) {
        assertTrue(e.getMessage().contains(IdmConceptRoleRequestService.ROLE_REQUEST_FIELD));
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) JSONObject(org.activiti.engine.impl.util.json.JSONObject) JSONException(org.activiti.engine.impl.util.json.JSONException) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ResultActions(org.springframework.test.web.servlet.ResultActions) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 33 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class VsRequestControllerRestTest method checkGetMethod.

@Test
public void checkGetMethod() throws Exception {
    SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
    IdmRoleDto roleOne = helper.createRole(helper.createName());
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    // Assign system to role
    helper.createRoleSystem(roleOne, virtualSystem);
    helper.assignRoles(helper.getPrimeContract(identity.getId()), false, roleOne);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(virtualSystem.getId());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto vsRequestDto = requests.get(0);
    String url = String.format("%s%s/%s", BaseDtoController.BASE_PATH, "/vs/requests", vsRequestDto.getId());
    ResultActions andExpect = getMockMvc().perform(get(url).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(jsonPath("$.id", equalTo(vsRequestDto.getId().toString())));
    assertNotNull(andExpect);
    String contentAsString = andExpect.andReturn().getResponse().getContentAsString();
    JSONObject tObject = new JSONObject(contentAsString);
    String embeddedString = tObject.get(EmbeddedDto.PROPERTY_EMBEDDED).toString();
    tObject = new JSONObject(embeddedString);
    String requestAsString = tObject.get(IdmConceptRoleRequestService.ROLE_REQUEST_FIELD).toString();
    assertNotNull(requestAsString);
    // Request as string cannot be transformed into class because:
    // Can not construct instance of eu.bcvsolutions.idm.core.api.dto.ResultModel
    // problem: abstract types either need to be mapped to concrete types, have custom deserializer,
    // or be instantiated with additional type information
    // IdmRoleRequestDto roleRequest = mapper.readValue(requestAsString, IdmRoleRequestDto.class);
    // assertNotNull(roleRequest);
    // Creator in embbedded
    assertTrue(requestAsString.contains("\"" + AbstractEntity_.creator.getName() + "\"" + ":{"));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) JSONObject(org.activiti.engine.impl.util.json.JSONObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ResultActions(org.springframework.test.web.servlet.ResultActions) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 34 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method modifiedDateTest.

@Test
public void modifiedDateTest() {
    SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
    IdmRoleDto roleOne = helper.createRole();
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    // Assign system to role
    helper.createRoleSystem(roleOne, virtualSystem);
    helper.assignRoles(helper.getPrimeContract(identity.getId()), false, roleOne);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(virtualSystem.getId());
    requestFilter.setUid(identity.getUsername());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    requestFilter.setModifiedAfter(ZonedDateTime.now().minusSeconds(10));
    requestFilter.setModifiedBefore(ZonedDateTime.now());
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    requestFilter.setModifiedAfter(ZonedDateTime.now().plusMinutes(10));
    requestFilter.setModifiedBefore(ZonedDateTime.now().plusMinutes(11));
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(0, requests.size());
    requestFilter.setModifiedAfter(ZonedDateTime.now().minusMinutes(10));
    requestFilter.setModifiedBefore(ZonedDateTime.now().minusMinutes(9));
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(0, requests.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 35 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method filterTest.

@Test
public void filterTest() {
    SysSystemDto virtualSystem = helper.createVirtualSystem(helper.createName());
    IdmRoleDto roleOne = helper.createRole();
    IdmIdentityDto identity = helper.createIdentity((GuardedString) null);
    IdmIdentityDto identity2 = helper.createIdentity((GuardedString) null);
    IdmIdentityDto identity3 = helper.createIdentity((GuardedString) null);
    IdmIdentityDto identity4 = helper.createIdentity((GuardedString) null);
    // Assign system to role
    helper.createRoleSystem(roleOne, virtualSystem);
    helper.assignRoles(helper.getPrimeContract(identity.getId()), false, roleOne);
    helper.assignRoles(helper.getPrimeContract(identity2.getId()), false, roleOne);
    helper.assignRoles(helper.getPrimeContract(identity3.getId()), false, roleOne);
    helper.assignRoles(helper.getPrimeContract(identity4.getId()), false, roleOne);
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(virtualSystem.getId());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(4, requests.size());
    VsRequestDto request = requests.get(0);
    requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    requestFilter.setOnlyArchived(true);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    requestFilter.setOnlyArchived(null);
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(3, requests.size());
    requestFilter.setConnectorKey(request.getConnectorKey());
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(3, requests.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)50 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)37 VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)37 Test (org.junit.Test)35 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)27 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)26 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)24 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)13 VsConnectorObjectDto (eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto)7 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 UUID (java.util.UUID)6 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 ArrayList (java.util.ArrayList)5 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)4 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)4 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)4 IcException (eu.bcvsolutions.idm.ic.exception.IcException)4 IcResultsHandler (eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler)4