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);
}
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));
}
}
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() + "\"" + ":{"));
}
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());
}
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());
}
Aggregations