restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
}
@Test
public void update() {
UserTO userTO = getSampleTO("g.h@t.com");
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(8L);
AttributeTO membershipAttr = new AttributeTO();
membershipAttr.setSchema("subscriptionDate");
membershipAttr.addValue("2009-08-18T16:33:12.203+0200");
membershipTO.addAttribute(membershipAttr);
userTO.addMembership(membershipTO);
userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
assertFalse(userTO.getDerivedAttributes().isEmpty());
assertEquals(1, userTO.getMemberships().size());
AttributeMod attributeMod = new AttributeMod();
attributeMod.setSchema("subscriptionDate");
attributeMod.addValueToBeAdded("2010-08-18T16:33:12.203+0200");
MembershipMod membershipMod = new MembershipMod();
membershipMod.setRole(8L);
membershipMod.addAttributeToBeUpdated(attributeMod);
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("newPassword");
userMod.addAttributeToBeRemoved("userId");
attributeMod = new AttributeMod();
attributeMod.setSchema("userId");
attributeMod.addValueToBeAdded("t.w@spre.net");
userMod.addAttributeToBeUpdated(attributeMod);
userMod.addAttributeToBeRemoved("fullname");
attributeMod = new AttributeMod();
attributeMod.setSchema("fullname");
attributeMod.addValueToBeAdded("g.h@t.com");
userMod.addAttributeToBeUpdated(attributeMod);
userMod.addDerivedAttributeToBeAdded("cn");
userMod.addMembershipToBeAdded(membershipMod);
userMod.addMembershipToBeRemoved(userTO.getMemberships().iterator().next().getId());
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
assertNotNull(userTO);
SyncopeUser passwordTestUser = new SyncopeUser();
passwordTestUser.setPassword("newPassword", CipherAlgorithm.MD5, 0);
assertEquals(passwordTestUser.getPassword(), userTO.getPassword());
assertEquals(1, userTO.getMemberships().size());
assertEquals(1, userTO.getMemberships().iterator().next().getAttributes().size());
assertFalse(userTO.getDerivedAttributes().isEmpty());
boolean userIdFound = false;
boolean fullnameFound = false;
for (AttributeTO attributeTO : userTO.getAttributes()) {
if ("userId".equals(attributeTO.getSchema())) {
userIdFound = true;
assertEquals(Collections.singletonList("t.w@spre.net"), attributeTO.getValues());
}
if ("fullname".equals(attributeTO.getSchema())) {