Search in sources :

Example 1 with Direction

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));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HttpURLConnection(java.net.HttpURLConnection) BeforeEach(org.junit.jupiter.api.BeforeEach) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Filter(org.eclipse.hono.service.management.Filter) MultiMap(io.vertx.core.MultiMap) Router(io.vertx.ext.web.Router) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Sort(org.eclipse.hono.service.management.Sort) ArgumentCaptor(org.mockito.ArgumentCaptor) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Vertx(io.vertx.core.Vertx) HttpHeaders(io.vertx.core.http.HttpHeaders) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Future(io.vertx.core.Future) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) Mockito.never(org.mockito.Mockito.never) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) Operator(org.eclipse.hono.service.management.Filter.Operator) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) DefaultFailureHandler(org.eclipse.hono.service.http.DefaultFailureHandler) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) Handler(io.vertx.core.Handler) Id(org.eclipse.hono.service.management.Id) Direction(org.eclipse.hono.service.management.Sort.Direction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Filter(org.eclipse.hono.service.management.Filter) HttpServerResponse(io.vertx.core.http.HttpServerResponse) HttpServerRequest(io.vertx.core.http.HttpServerRequest) Sort(org.eclipse.hono.service.management.Sort) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Span (io.opentracing.Span)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 MultiMap (io.vertx.core.MultiMap)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpHeaders (io.vertx.core.http.HttpHeaders)1 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpServerRequest (io.vertx.core.http.HttpServerRequest)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 HttpServerRequestInternal (io.vertx.core.http.impl.HttpServerRequestInternal)1 JsonObject (io.vertx.core.json.JsonObject)1 Router (io.vertx.ext.web.Router)1 HttpURLConnection (java.net.HttpURLConnection)1 List (java.util.List)1 Optional (java.util.Optional)1 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)1 DefaultFailureHandler (org.eclipse.hono.service.http.DefaultFailureHandler)1 Filter (org.eclipse.hono.service.management.Filter)1