use of org.eclipse.hono.service.management.Sort.Direction in project hono by eclipse.
the class DelegatingDeviceManagementHttpEndpointTest method testSearchDevicesSucceedsWithSearchCriteria.
/**
* Verifies that the endpoint uses search criteria provided in a request's query parameters.
*/
@Test
public void testSearchDevicesSucceedsWithSearchCriteria() {
final HttpServerResponse response = newResponse();
requestParams.add(RegistryManagementConstants.PARAM_PAGE_SIZE, "10");
requestParams.add(RegistryManagementConstants.PARAM_PAGE_OFFSET, "50");
requestParams.add(RegistryManagementConstants.PARAM_FILTER_JSON, "{\"field\":\"/manufacturer\",\"value\":\"ACME*\"}");
requestParams.add(RegistryManagementConstants.PARAM_SORT_JSON, "{\"field\":\"/manufacturer\",\"direction\":\"desc\"}");
final HttpServerRequest request = newRequest(HttpMethod.GET, "/v1/devices/mytenant", requestHeaders, requestParams, response);
router.handle(request);
verify(response).setStatusCode(HttpURLConnection.HTTP_OK);
verify(service).searchDevices(eq("mytenant"), eq(10), eq(50), argThat(filters -> {
if (filters.isEmpty()) {
return false;
} else {
final Filter filter = filters.get(0);
return "/manufacturer".equals(filter.getField().toString()) && "ACME*".equals(filter.getValue()) && Operator.eq == filter.getOperator();
}
}), argThat(sortOptions -> {
if (sortOptions.isEmpty()) {
return false;
} else {
final Sort sortOption = sortOptions.get(0);
return "/manufacturer".equals(sortOption.getField().toString()) && Direction.DESC == sortOption.getDirection();
}
}), any(Span.class));
}
Aggregations