}
@Test
public void issue186() {
// 1. create an user with strict mandatory attributes only
UserTO userTO = new UserTO();
userTO.setUsername("issue186@syncope.apache.org");
userTO.setPassword("password");
AttributeTO attributeTO = new AttributeTO();
attributeTO.setSchema("userId");
attributeTO.addValue("issue186@syncope.apache.org");
userTO.addAttribute(attributeTO);
attributeTO = new AttributeTO();
attributeTO.setSchema("fullname");
attributeTO.addValue("issue186");
userTO.addAttribute(attributeTO);
attributeTO = new AttributeTO();
attributeTO.setSchema("surname");
attributeTO.addValue("issue186");
userTO.addAttribute(attributeTO);
userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
assertNotNull(userTO);
assertTrue(userTO.getResources().isEmpty());
// 2. update assigning a resource forcing mandatory constraints: must
// fail with RequiredValuesMissing
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("newPassword");
userMod.addResourceToBeAdded("ws-target-resource-2");
SyncopeClientException sce = null;
try {
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
} catch (SyncopeClientCompositeErrorException scce) {
sce = scce.getException(SyncopeClientExceptionType.RequiredValuesMissing);
}
assertNotNull(sce);
// 3. update assigning a resource NOT forcing mandatory constraints
// AND primary: must fail with PropagationException
userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("newPassword");
userMod.addResourceToBeAdded("ws-target-resource-1");
sce = null;
try {
userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
} catch (SyncopeClientCompositeErrorException scce) {
sce = scce.getException(SyncopeClientExceptionType.Propagation);
}
assertNotNull(sce);
// 4. update assigning a resource NOT forcing mandatory constraints
// BUT not primary: must succeed
userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("newPassword");
userMod.addResourceToBeAdded("resource-db");
sce = null;
try {