UserTO actual = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
assertNotNull(actual);
assertEquals(2, actual.getMemberships().size());
ConnObjectTO connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class,
"resource-ldap",
userTO.getUsername());
assertNotNull(connObjectTO);
postalAddress = connObjectTO.getAttributeMap().get("postalAddress");
assertNotNull(postalAddress);
assertEquals(1, postalAddress.getValues().size());
assertEquals("postalAddress", postalAddress.getValues().get(0));
AttributeTO title = connObjectTO.getAttributeMap().get("title");
assertNotNull(title);
assertEquals(2, title.getValues().size());
assertTrue(title.getValues().contains("r12") && title.getValues().contains("r13"));
// -----------------------------------
// Remove the first membership and check for membership attr propagation and role attr propagation
// -----------------------------------
UserMod userMod = new UserMod();
userMod.setId(actual.getId());
MembershipTO membershipTO = actual.getMemberships().get(0).getRoleId() == 12L
? actual.getMemberships().get(0) : actual.getMemberships().get(1);
userMod.addMembershipToBeRemoved(membershipTO.getId());
actual = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
assertNotNull(actual);
assertEquals(1, actual.getMemberships().size());
connObjectTO = restTemplate.getForObject(
BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
ConnObjectTO.class,
"resource-ldap",
userTO.getUsername());
assertNotNull(connObjectTO);
postalAddress = connObjectTO.getAttributeMap().get("postalAddress");
assertTrue(postalAddress == null
|| postalAddress.getValues().isEmpty() || StringUtils.hasText(postalAddress.getValues().get(0)));
title = connObjectTO.getAttributeMap().get("title");
assertNotNull(title);
assertEquals(1, title.getValues().size());
assertTrue(title.getValues().contains("r13"));
// -----------------------------------
}