Search in sources :

Example 36 with ListResponse

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

the class PaginationUserSearchTest method search1.

@Test
public void search1() {
    // Issue a default request except for a filter and reducing the attributes returned
    sr = new SearchRequest();
    sr.setFilter("name.familyName co \"Filter\"");
    // Couchbase result set order is not deterministic, requires ORDER BY to workaround it
    sr.setSortBy("id");
    sr.setAttributes("meta.location");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // Store for further comparison
    listResponse = response.readEntity(ListResponse.class);
    assertEquals(listResponse.getResources().size(), listResponse.getTotalResults());
}
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) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 37 with ListResponse

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

the class PaginationUserSearchTest method search2.

@Test(dependsOnMethods = "search1")
public void search2() {
    // Issue the request specifiying index and count
    sr.setStartIndex(1);
    sr.setCount(listResponse.getTotalResults());
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse anotherLR = response.readEntity(ListResponse.class);
    // number of results should be the same as in original listResponse (first test)
    assertEquals(listResponse.getTotalResults(), anotherLR.getTotalResults());
    // The page return should contain all results
    assertEquals(listResponse.getTotalResults(), anotherLR.getItemsPerPage());
    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)

Example 38 with ListResponse

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

the class PaginationUserSearchTest method search4.

@Test(dependsOnMethods = "search3")
public void search4() {
    // Issue a request disregarding resources (only total is of interest)
    sr.setStartIndex(null);
    sr.setCount(0);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse anotherLR = response.readEntity(ListResponse.class);
    // means no existing
    assertEquals(anotherLR.getItemsPerPage(), 0);
    assertEquals(anotherLR.getTotalResults(), listResponse.getTotalResults());
    // Verify resources weren't serialized
    assertNull(anotherLR.getResources());
}
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)

Example 39 with ListResponse

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

the class PaginationUserSearchTest method search3.

@Test(dependsOnMethods = "search2")
public void search3() {
    int rounds = 3;
    int ipp = listResponse.getTotalResults() / 3;
    // Make several requests changing start index, leaving count to be fixed valued
    for (int i = 0; i < rounds; i++) {
        int startIndex = rounds * (1 + i) + 1;
        sr.setStartIndex(startIndex);
        sr.setCount(ipp);
        Response response = client.searchUsersPost(sr);
        assertEquals(response.getStatus(), OK.getStatusCode());
        ListResponse anotherLR = response.readEntity(ListResponse.class);
        // Items per page should be the same as count supplied above
        assertEquals(anotherLR.getItemsPerPage(), ipp);
        assertEquals(anotherLR.getStartIndex(), startIndex);
        // Determine if current results contain the same elements as in original listResponse
        Set<String> ids = new LinkedHashSet<>();
        Set<String> ids2 = new LinkedHashSet<>();
        for (int j = 0; j < ipp; j++) {
            ids.add(listResponse.getResources().get(j + startIndex - 1).getId());
            ids2.add(anotherLR.getResources().get(j).getId());
            assertNotNull(anotherLR.getResources().get(j).getMeta().getLocation());
        }
        assertTrue(ids.containsAll(ids2));
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) LinkedHashSet(java.util.LinkedHashSet) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 40 with ListResponse

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

the class PairwiseIdentifiersTest method queryAndRemoval.

@Test
public void queryAndRemoval() throws Exception {
    // Get a list (of at most 1 user) who has a persisted pairwise identifier
    Response response = client.searchUsers("pairwiseIdentifiers pr", null, 1, null, null, "pairwiseIdentifiers, id", null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse lr = response.readEntity(ListResponse.class);
    // If the list is empty do nothing (successful test)
    if (lr.getItemsPerPage() > 0) {
        UserResource user = (UserResource) lr.getResources().get(0);
        assertNotNull(user.getPairwiseIdentifiers());
        // Prepare the removal of the user's PPIDs
        PatchOperation operation = new PatchOperation();
        operation.setOperation("remove");
        operation.setPath("pairwiseIdentitifers");
        PatchRequest pr = new PatchRequest();
        pr.setOperations(Collections.singletonList(operation));
        response = client.patchUser(pr, user.getId(), "pairwiseIdentifiers", null);
        assertEquals(response.getStatus(), OK.getStatusCode());
        // Ensure they are not there anymore.
        user = response.readEntity(UserResource.class);
        assertNull(user.getPairwiseIdentifiers());
    // This test does not guarantee the ou=pairwiseIdentifiers sub-branch disappears... only the jsPPID LDAP attribute
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

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