Search in sources :

Example 16 with ListResponse

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

the class SchemasTest method init.

@BeforeTest
public void init() throws Exception {
    Response response = client.getSchemas();
    listResponse = response.readEntity(ListResponse.class);
    assertTrue(listResponse.getTotalResults() > 0);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) BeforeTest(org.testng.annotations.BeforeTest)

Example 17 with ListResponse

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

the class FidoU2fDeviceTest method search.

@Test
public void search() {
    logger.debug("Searching all fido u2f devices");
    Response response = client.searchDevices(null, "application pr", null, null, null, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    // Work upon the first device whose deviceData is empty
    Optional<FidoDeviceResource> opt = listResponse.getResources().stream().map(FidoDeviceResource.class::cast).filter(dev -> dev.getDeviceData() == null).findAny();
    assertTrue(opt.isPresent());
    device = opt.get();
    logger.debug("First device {} picked", device.getId());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) BeanUtils(org.apache.commons.beanutils.BeanUtils) ListResponse(io.jans.scim.model.scim2.ListResponse) IntrospectUtil(io.jans.scim.model.scim2.util.IntrospectUtil) Optional(java.util.Optional) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) Status(javax.ws.rs.core.Response.Status) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) ListResponse(io.jans.scim.model.scim2.ListResponse) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 18 with ListResponse

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

the class ComplexSearchUserTest method searchExcludedAttributesParam.

@Test
public void searchExcludedAttributesParam() {
    int count = 3;
    List<String> attrList = Arrays.asList("x509Certificates", "entitlements", "roles", "ims", "phoneNumbers", "addresses", "emails", "groups");
    logger.debug("Searching at most {} users using POST verb", count);
    logger.debug("Sorted by displayName ascending");
    logger.debug("Excluding the attributes {}", attrList);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("displayName pr");
    sr.setSortBy("displayName");
    sr.setSortOrder("descending");
    // Generate a string with the attributes to exclude
    sr.setExcludedAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
    sr.setCount(count);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources().size() < count)
        logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
    else {
        // Obtain an array of results
        UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
        assertEquals(users.length, count);
        // Verify attributes were excluded
        for (UserResource u : users) {
            assertNull(u.getX509Certificates());
            assertNull(u.getEntitlements());
            assertNull(u.getRoles());
            assertNull(u.getIms());
            assertNull(u.getPhoneNumbers());
            assertNull(u.getAddresses());
            assertNull(u.getEmails());
        }
        boolean correctSorting = true;
        for (int i = 1; i < users.length && correctSorting; i++) {
            String displayName = users[i - 1].getDisplayName();
            String displayName2 = users[i].getDisplayName();
            // Check if second string is less or equal than first
            correctSorting = displayName.compareTo(displayName2) >= 0;
        }
        if (!correctSorting) {
            // LDAP may ignore case sensitivity, try again using lowercasing
            correctSorting = true;
            for (int i = 1; i < users.length && correctSorting; i++) {
                String displayName = users[i - 1].getDisplayName().toLowerCase();
                String displayName2 = users[i].getDisplayName().toLowerCase();
                // Check if second string is less or equal than first
                correctSorting = displayName.compareTo(displayName2) >= 0;
            }
        }
        assertTrue(correctSorting);
    }
}
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 19 with ListResponse

use of io.jans.scim.model.scim2.ListResponse 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 20 with ListResponse

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

the class PaginationUserSearchTest method search5.

@Test(dependsOnMethods = "search4")
public void search5() {
    // Request more resources than existing
    int existing = listResponse.getTotalResults();
    sr.setStartIndex(null);
    sr.setCount(1 + existing);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse anotherLR = response.readEntity(ListResponse.class);
    assertEquals(anotherLR.getTotalResults(), existing);
    assertEquals(anotherLR.getItemsPerPage(), existing);
    assertEquals(anotherLR.getStartIndex(), 1);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

Response (javax.ws.rs.core.Response)38 ListResponse (io.jans.scim.model.scim2.ListResponse)36 Test (org.testng.annotations.Test)26 UserBaseTest (io.jans.scim2.client.UserBaseTest)16 SearchRequest (io.jans.scim.model.scim2.SearchRequest)12 UserResource (io.jans.scim.model.scim2.user.UserResource)11 URI (java.net.URI)11 BaseTest (io.jans.scim2.client.BaseTest)10 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)9 DefaultValue (javax.ws.rs.DefaultValue)8 HeaderParam (javax.ws.rs.HeaderParam)8 Produces (javax.ws.rs.Produces)8 ArrayList (java.util.ArrayList)7 GET (javax.ws.rs.GET)7 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 RejectFilterParam (io.jans.scim.service.scim2.interceptor.RejectFilterParam)2