MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(8L);
userTO.addMembership(membershipTO);
SyncopeClientCompositeErrorException ex = null;
try {
// 1. create user without type (mandatory by UserSchema)
restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
} catch (SyncopeClientCompositeErrorException e) {
ex = e;
}
assertNotNull(ex);
assertNotNull(ex.getException(SyncopeClientExceptionType.RequiredValuesMissing));
AttributeTO fType = new AttributeTO();
fType.setSchema("type");
fType.addValue("F");
userTO.addAttribute(fType);
AttributeTO surname = null;
for (AttributeTO attributeTO : userTO.getAttributes()) {
if ("surname".equals(attributeTO.getSchema())) {
surname = attributeTO;
}
}
userTO.removeAttribute(surname);
// 2. create user without surname (mandatory when type == 'F')
ex = null;
try {
restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
} catch (SyncopeClientCompositeErrorException e) {
ex = e;
}
assertNotNull(ex);
assertNotNull(ex.getException(SyncopeClientExceptionType.RequiredValuesMissing));
}