use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class PatchReplaceUserTest method jsonNoPathPatch2.
@Parameters({ "user_patchreplace_2" })
@Test(dependsOnMethods = "jsonNoPathPatch1")
public void jsonNoPathPatch2(String patchRequest) {
Response response = client.patchUser(patchRequest, user.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
UserResource other = response.readEntity(usrClass);
assertNotEquals(user.getName().getHonorificPrefix(), other.getName().getHonorificPrefix());
assertNotEquals(user.getName().getHonorificSuffix(), other.getName().getHonorificSuffix());
assertNotEquals(user.getName().getFormatted(), other.getName().getFormatted());
// Verify change in the streetAddress
Address adr = other.getAddresses().get(0);
assertNotEquals(user.getAddresses().get(0).getStreetAddress(), adr.getStreetAddress());
// Verify other attributes were nulled
assertNull(adr.getPostalCode());
assertNull(adr.getRegion());
// Verify change in number of phone numbers
assertNotEquals(user.getPhoneNumbers().size(), other.getPhoneNumbers().size());
// Verify new user has different phone numbers
String phone = user.getPhoneNumbers().get(0).getValue();
assertTrue(other.getPhoneNumbers().stream().map(PhoneNumber::getValue).noneMatch(phone::equals));
// Verify x509Certs disappeared
assertNull(other.getX509Certificates());
// Verify "roles" are still there intact
assertEquals(user.getRoles().size(), other.getRoles().size());
assertEquals(user.getRoles().get(0).getValue(), other.getRoles().get(0).getValue());
user = other;
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class SimpleSearchUserTest method searchComplexAttrPost.
@Test(dependsOnMethods = "create", groups = "search")
public void searchComplexAttrPost() {
String givenName = user.getName().getGivenName();
logger.debug("Searching user with attribute givenName = {} using POST verb", givenName);
SearchRequest sr = new SearchRequest();
sr.setFilter("name.givenName eq \"" + givenName + "\"");
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
assertTrue(listResponse.getResources().size() > 0);
// Retrieve first user in results
UserResource other = listResponse.getResources().stream().map(usrClass::cast).findFirst().get();
assertEquals(other.getName().getGivenName(), givenName);
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class SimpleSearchUserTest method searchComplexMultivaluedPost.
@Test(dependsOnMethods = "create", groups = "search")
public void searchComplexMultivaluedPost() {
String ghost = user.getEmails().get(0).getValue();
final String host = ghost.substring(ghost.indexOf("@") + 1);
logger.debug("Searching user with attribute emails.value like {} or phone numbers with type unassigned or value containing '+' using POST verb", host);
SearchRequest sr = new SearchRequest();
sr.setFilter("emails[value ew \"" + host + "\"] or urn:ietf:params:scim:schemas:core:2.0:User:phoneNumbers[value co \"+\" or type eq null]");
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
assertTrue(listResponse.getResources().size() > 0);
// Retrieve first user in results
UserResource other = listResponse.getResources().stream().map(usrClass::cast).findFirst().get();
boolean cond1 = false, cond2 = false, cond3 = false;
if (other.getEmails() != null) {
cond1 = other.getEmails().stream().anyMatch(mail -> mail.getValue().endsWith(host));
}
if (other.getPhoneNumbers() != null) {
cond2 = other.getPhoneNumbers().stream().anyMatch(phone -> phone.getValue().contains("+"));
cond3 = other.getPhoneNumbers().stream().anyMatch(phone -> phone.getType() == null);
}
assertTrue(cond1 || cond2 || cond3);
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class AverageUserTest method updateWithObject2.
@Test(dependsOnMethods = "updateWithObject1")
public void updateWithObject2() {
UserResource aUser = new UserResource();
aUser.setEmails(user.getEmails());
aUser.setPhoneNumbers(user.getPhoneNumbers());
// Change some canonical values
aUser.getEmails().get(0).setType(Email.Type.HOME);
aUser.getPhoneNumbers().get(0).setType("fax");
PhoneNumber pager = new PhoneNumber();
pager.setValue("+1 234 566 9999");
pager.setType(PhoneNumber.Type.PAGER);
aUser.getPhoneNumbers().add(pager);
Response response = client.updateUser(aUser, user.getId(), "emails, addresses, phoneNumbers, userName", null);
user = response.readEntity(UserResource.class);
assertEquals(user.getEmails().get(0).getType(), Email.Type.HOME.name().toLowerCase());
assertEquals(user.getPhoneNumbers().get(0).getType(), PhoneNumber.Type.FAX.name().toLowerCase());
assertEquals(user.getPhoneNumbers().get(1).getType(), PhoneNumber.Type.PAGER.name().toLowerCase());
assertNull(user.getPreferredLanguage());
logger.debug("Updated user {}", user.getUserName());
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class AverageUserTest method updateWithObject1.
@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject1() throws Exception {
UserResource clone = getDeepCloneUsr(user);
clone.setPreferredLanguage("en_US");
clone.getPhoneNumbers().remove(0);
// Means no change
clone.setAddresses(null);
// Means role will have to disappear
clone.setRoles(new ArrayList<>());
Group group = new Group();
group.setValue("Dummy ID");
// will be ignored: group membership changes MUST be applied via /Groups endpoint
clone.setGroups(Collections.singletonList(group));
logger.debug("Updating user {}", clone.getUserName());
Response response = client.updateUser(clone, clone.getId(), null, "meta");
assertEquals(response.getStatus(), OK.getStatusCode());
user = response.readEntity(usrClass);
assertNotNull(user.getPreferredLanguage());
assertEquals(user.getPreferredLanguage(), clone.getPreferredLanguage());
assertEquals(user.getPhoneNumbers().size(), clone.getPhoneNumbers().size());
assertFalse(user.getAddresses().isEmpty());
assertNull(user.getRoles());
assertNull(user.getGroups());
logger.debug("Updated user {}", user.getName().getGivenName());
// Double check update did take update in the original source (eg. LDAP):
String json = response.readEntity(String.class);
response = client.getUserById(clone.getId(), null, "meta");
// both json contents should be the same since meta attribute was removed and serialization involves UserResource class
assertEquals(json, response.readEntity(String.class));
}
Aggregations