Search in sources :

Example 21 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class ComplexSearchUserTest method searchSortByDate.

// This test is disabled to avoid problems in attribute excludeMetaLastMod being inconsistent with updatedAt in testing server
// @Test
public void searchSortByDate() {
    SearchRequest sr = new SearchRequest();
    sr.setFilter("userName pr");
    sr.setSortBy("meta.lastModified");
    sr.setAttributes(Collections.singletonList(sr.getSortBy()));
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
    for (int i = 1; i < users.length; i++) {
        String lastMod1 = users[i - 1].getMeta() == null ? null : users[i - 1].getMeta().getLastModified();
        String lastMod2 = users[i].getMeta() == null ? null : users[i].getMeta().getLastModified();
        if (// Both being non null is OK
        lastMod1 != null)
            assertNotNull(lastMod2);
        if (// If second is null, first must be
        lastMod2 == null)
            assertNull(lastMod1);
        if (lastMod1 != null && lastMod2 != null) {
            ZonedDateTime dt1 = ZonedDateTime.parse(lastMod1);
            ZonedDateTime dt2 = ZonedDateTime.parse(lastMod2);
            assertTrue(dt1.isEqual(dt2) || dt1.isBefore(dt2));
        }
    }
}
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) ZonedDateTime(java.time.ZonedDateTime) UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 22 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class PatchDeleteUserTest method delete1.

@Parameters({ "user_patchdelete" })
@Test(dependsOnMethods = "createForDel")
public void delete1(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    for (int i = 0; i < 2; i++) {
        assertNull(other.getName().getMiddleName());
        assertNull(other.getNickName());
        assertNull(other.getEntitlements());
        assertNull(other.getAddresses().get(0).getPostalCode());
        assertNull(other.getAddresses().get(0).getLocality());
        assertNotNull(other.getAddresses().get(0).getStreetAddress());
        // Double check
        response = client.getUserById(user.getId(), null, null);
        other = response.readEntity(usrClass);
    }
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 23 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class PatchReplaceUserTest method jsonPathPatch1.

@Parameters({ "user_patchreplace_3" })
@Test(dependsOnMethods = "jsonNoPathPatch2")
public void jsonPathPatch1(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    // Verify display name changed
    assertNotEquals(user.getDisplayName(), other.getDisplayName());
    // Verify some name components changed
    assertNotEquals(user.getName().getFamilyName(), other.getName().getFamilyName());
    assertNotEquals(user.getName().getMiddleName(), other.getName().getMiddleName());
    assertNotEquals(user.getName().getGivenName(), other.getName().getGivenName());
    assertEquals(user.getName().getHonorificPrefix(), other.getName().getHonorificPrefix());
    assertEquals(user.getName().getHonorificSuffix(), other.getName().getHonorificSuffix());
    // Verify is now active
    assertTrue(other.getActive());
    user = other;
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 24 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class PatchValueFilterUserTest method getDummyUser.

private UserResource getDummyUser() {
    user = new UserResource();
    user.setUserName("" + System.currentTimeMillis());
    user.setEmails(new ArrayList<>());
    user.setPhoneNumbers(new ArrayList<>());
    Email email = new Email();
    email.setValue("bjane@gluu.org");
    email.setDisplay("bjane");
    email.setPrimary(true);
    email.setType("work");
    user.getEmails().add(email);
    email = new Email();
    email.setValue("bjane@acme.org");
    email.setDisplay("bjane acme");
    email.setType("hobby");
    user.getEmails().add(email);
    PhoneNumber pn = new PhoneNumber();
    pn.setValue("+57 1234 56789");
    pn.setType("home");
    user.getPhoneNumbers().add(pn);
    pn = new PhoneNumber();
    pn.setValue("+1 1234 56789");
    pn.setType("work");
    pn.setPrimary(true);
    user.getPhoneNumbers().add(pn);
    Address address = new Address();
    address.setCountry("EG");
    address.setPrimary(false);
    address.setRegion("Somewhere");
    address.setStreetAddress("59 Acacia avenue");
    address.setLocality("Donington");
    user.setAddresses(Collections.singletonList(address));
    return user;
}
Also used : Email(io.jans.scim.model.scim2.user.Email) Address(io.jans.scim.model.scim2.user.Address) UserResource(io.jans.scim.model.scim2.user.UserResource) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber)

Example 25 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class FullUserTest method update.

@Parameters("user_full_update")
@Test(dependsOnMethods = "createFull")
public void update(String json) {
    logger.debug("Updating user {} with json", user.getUserName());
    Response response = client.updateUser(json, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    CustomAttributes custAttrs1 = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    CustomAttributes custAttrs2 = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify scimCustomFirst changed
    assertNotEquals(custAttrs1.getValue("scimCustomFirst", String.class), custAttrs2.getValue("scimCustomFirst", String.class));
    // Verify a new scimCustomSecond value
    List<Date> col1 = custAttrs1.getValues("scimCustomSecond", Date.class);
    List<Date> col2 = custAttrs2.getValues("scimCustomSecond", Date.class);
    assertNotEquals(col1.size(), col2.size());
    // Verify scimCustomThird is the same
    assertEquals(custAttrs1.getValue("scimCustomThird", Integer.class), custAttrs2.getValue("scimCustomThird", Integer.class));
    // Verify change in emails, addresses and phoneNumbers
    assertNotEquals(user.getEmails().size(), other.getEmails().size());
    assertNotEquals(user.getAddresses().size(), other.getAddresses().size());
    assertNotEquals(user.getPhoneNumbers().size(), other.getPhoneNumbers().size());
    // Verify x509Certificates disappeared
    assertNull(other.getX509Certificates());
    // Verify no change in user type
    assertEquals(user.getUserType(), other.getUserType());
    user = other;
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest)

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