Search in sources :

Example 46 with UserResource

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;
}
Also used : Response(javax.ws.rs.core.Response) Address(io.jans.scim.model.scim2.user.Address) InstantMessagingAddress(io.jans.scim.model.scim2.user.InstantMessagingAddress) UserResource(io.jans.scim.model.scim2.user.UserResource) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 47 with UserResource

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);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 48 with UserResource

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);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) UserResource(io.jans.scim.model.scim2.user.UserResource) SearchRequest(io.jans.scim.model.scim2.SearchRequest) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) ListResponse(io.jans.scim.model.scim2.ListResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) Instant(java.time.Instant) Status(javax.ws.rs.core.Response.Status) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 49 with UserResource

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());
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 50 with UserResource

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));
}
Also used : Response(javax.ws.rs.core.Response) Group(io.jans.scim.model.scim2.user.Group) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

UserResource (io.jans.scim.model.scim2.user.UserResource)49 Response (javax.ws.rs.core.Response)47 Test (org.testng.annotations.Test)37 UserBaseTest (io.jans.scim2.client.UserBaseTest)34 ListResponse (io.jans.scim.model.scim2.ListResponse)21 SearchRequest (io.jans.scim.model.scim2.SearchRequest)14 Parameters (org.testng.annotations.Parameters)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Path (javax.ws.rs.Path)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)6 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)6 SkipTest (io.jans.scim2.listener.SkipTest)6 URI (java.net.URI)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Status (javax.ws.rs.core.Response.Status)6 BeforeTest (org.testng.annotations.BeforeTest)6 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)5 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)5