assertNotNull(userTO);
assertFalse(userTO.getPropagationTOs().isEmpty());
assertEquals("ws-target-resource-2", userTO.getPropagationTOs().get(0).getResourceName());
assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationTOs().get(0).getStatus());
ConnObjectTO connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
assertEquals("virtualvalue", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user virtual attribute and check virtual attribute value update propagation
// ----------------------------------
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
AttributeMod attrMod = new AttributeMod();
attrMod.setSchema("virtualdata");
attrMod.addValueToBeRemoved("virtualvalue");
attrMod.addValueToBeAdded("virtualvalue2");
userMod.addVirtualAttributeToBeUpdated(attrMod);
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
assertNotNull(userTO);
assertFalse(userTO.getPropagationTOs().isEmpty());
assertEquals("ws-target-resource-2", userTO.getPropagationTOs().get(0).getResourceName());
assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationTOs().get(0).getStatus());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
// ----------------------------------
// ----------------------------------
// suspend/reactivate user and check virtual attribute value (unchanged)
// ----------------------------------
userTO = restTemplate.getForObject(BASE_URL + "user/suspend/" + userTO.getId(), UserTO.class);
assertEquals("suspended", userTO.getStatus());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
userTO = restTemplate.getForObject(BASE_URL + "user/reactivate/" + userTO.getId(), UserTO.class);
assertEquals("active", userTO.getStatus());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
// ----------------------------------
// ----------------------------------
// update user attribute and check virtual attribute value (unchanged)
// ----------------------------------
userMod = new UserMod();
userMod.setId(userTO.getId());
attrMod = new AttributeMod();
attrMod.setSchema("surname");
attrMod.addValueToBeRemoved("Surname");
attrMod.addValueToBeAdded("Surname2");
userMod.addAttributeToBeUpdated(attrMod);
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
assertNotNull(userTO);
assertFalse(userTO.getPropagationTOs().isEmpty());
assertEquals("ws-target-resource-2", userTO.getPropagationTOs().get(0).getResourceName());
assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationTOs().get(0).getStatus());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
assertEquals("Surname2", connObjectTO.getAttributeMap().get("SURNAME").getValues().get(0));
// attribute "name" mapped on virtual attribute "virtualdata" shouldn't be changed
assertFalse(connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
assertEquals("virtualvalue2", connObjectTO.getAttributeMap().get("NAME").getValues().get(0));
// ----------------------------------
// ----------------------------------
// remove user virtual attribute and check virtual attribute value (reset)
// ----------------------------------
userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.addVirtualAttributeToBeRemoved("virtualdata");
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
assertNotNull(userTO);
assertTrue(userTO.getVirtualAttributes().isEmpty());
assertFalse(userTO.getPropagationTOs().isEmpty());
assertEquals("ws-target-resource-2", userTO.getPropagationTOs().get(0).getResourceName());
assertEquals(PropagationTaskExecStatus.SUBMITTED, userTO.getPropagationTOs().get(0).getStatus());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class, "ws-target-resource-2", userTO.getUsername());
assertNotNull(connObjectTO);
// attribute "name" mapped on virtual attribute "virtualdata" should be reset
assertTrue(connObjectTO.getAttributeMap().get("NAME").getValues() == null
|| connObjectTO.getAttributeMap().get("NAME").getValues().isEmpty());
// ----------------------------------
}