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());
}
Aggregations