AttributeTO csvuserid = new AttributeTO();
csvuserid.setSchema("csvuserid");
userTO.addDerivedAttribute(csvuserid);
MembershipTO memb12 = new MembershipTO();
memb12.setRoleId(12L);
AttributeTO postalAddress = new AttributeTO();
postalAddress.setSchema("postalAddress");
postalAddress.addValue("postalAddress");
memb12.addAttribute(postalAddress);
userTO.addMembership(memb12);
MembershipTO memb13 = new MembershipTO();
memb13.setRoleId(13L);
userTO.addMembership(memb13);
userTO.addResource("resource-ldap");
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());