Search in sources :

Example 6 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMITCase method search.

@Test
public void search() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    // invalid filter
    Response response = webClient().path("Groups").query("filter", "invalid").get();
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), error.getStatus());
    assertEquals(ErrorType.invalidFilter, error.getScimType());
    // eq
    response = webClient().path("Groups").query("filter", "displayName eq \"additional\"").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMGroup> groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(groups);
    assertEquals(1, groups.getTotalResults());
    SCIMGroup additional = groups.getResources().get(0);
    assertEquals("additional", additional.getDisplayName());
    // eq via POST
    SCIMSearchRequest request = new SCIMSearchRequest("displayName eq \"additional\"", null, null, null, null);
    response = webClient().path("Groups").path("/.search").post(request);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    groups = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(groups);
    assertEquals(1, groups.getTotalResults());
    additional = groups.getResources().get(0);
    assertEquals("additional", additional.getDisplayName());
    // gt
    UserTO newUser = userService.create(UserITCase.getUniqueSampleTO("scimsearch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    Date value = new Date(newUser.getCreationDate().getTime() - 1000);
    response = webClient().path("Users").query("filter", "meta.created gt \"" + DATE_FORMAT.get().format(value) + "\"").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMUser> users = response.readEntity(new GenericType<ListResponse<SCIMUser>>() {
    });
    assertNotNull(users);
    assertEquals(1, users.getTotalResults());
    SCIMUser newSCIMUser = users.getResources().get(0);
    assertEquals(newUser.getUsername(), newSCIMUser.getUserName());
}
Also used : GenericType(javax.ws.rs.core.GenericType) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) Date(java.util.Date) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) UserTO(org.apache.syncope.common.lib.to.UserTO) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) SCIMSearchRequest(org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SCIMError (org.apache.syncope.ext.scimv2.api.data.SCIMError)6 Response (javax.ws.rs.core.Response)4 ListResponse (org.apache.syncope.ext.scimv2.api.data.ListResponse)4 Test (org.junit.jupiter.api.Test)4 SCIMGroup (org.apache.syncope.ext.scimv2.api.data.SCIMGroup)3 SCIMUser (org.apache.syncope.ext.scimv2.api.data.SCIMUser)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Date (java.util.Date)1 ValidationException (javax.validation.ValidationException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 GenericType (javax.ws.rs.core.GenericType)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)1 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)1 Member (org.apache.syncope.ext.scimv2.api.data.Member)1 SCIMSearchRequest (org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest)1