userTO = userService.update(userMod.getId(), userMod);
}
@Test
public void update() {
UserTO userTO = getUniqueSampleTO("g.h@t.com");
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(8L);
membershipTO.addAttribute(attributeTO("subscriptionDate", "2009-08-18T16:33:12.203+0200"));
userTO.addMembership(membershipTO);
userTO = createUser(userTO);
assertFalse(userTO.getDerivedAttributes().isEmpty());
assertEquals(1, userTO.getMemberships().size());
MembershipMod membershipMod = new MembershipMod();
membershipMod.setRole(8L);
membershipMod.addAttributeToBeUpdated(attributeMod("subscriptionDate", "2010-08-18T16:33:12.203+0200"));
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("new2Password");
userMod.addAttributeToBeRemoved("userId");
String newUserId = getUUIDString() + "t.w@spre.net";
userMod.addAttributeToBeUpdated(attributeMod("userId", newUserId));
userMod.addAttributeToBeRemoved("fullname");
String newFullName = getUUIDString() + "g.h@t.com";
userMod.addAttributeToBeUpdated(attributeMod("fullname", newFullName));
userMod.addDerivedAttributeToBeAdded("cn");
userMod.addMembershipToBeAdded(membershipMod);
userMod.addMembershipToBeRemoved(userTO.getMemberships().iterator().next().getId());
userTO = userService.update(userMod.getId(), userMod);
assertNotNull(userTO);
SyncopeUser passwordTestUser = new SyncopeUser();
passwordTestUser.setPassword("new2Password", CipherAlgorithm.SHA1, 0);
assertEquals(passwordTestUser.getPassword(), userTO.getPassword());
assertEquals(1, userTO.getMemberships().size());
assertEquals(1, userTO.getMemberships().iterator().next().getAttributes().size());
assertFalse(userTO.getDerivedAttributes().isEmpty());
AttributeTO userIdAttr = getManadatoryAttrByName(userTO.getAttributes(), "userId");
assertEquals(Collections.singletonList(newUserId), userIdAttr.getValues());
AttributeTO fullNameAttr = getManadatoryAttrByName(userTO.getAttributes(), "fullname");
assertEquals(Collections.singletonList(newFullName), fullNameAttr.getValues());
}