Search in sources :

Example 11 with SearchResult

use of org.eclipse.hono.service.management.SearchResult in project hono by eclipse.

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithWildCardToMatchMultipleCharacters.

/**
 * Verifies that a request to search tenants with filters containing the wildcard character '*'
 * succeeds and matching tenants are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithWildCardToMatchMultipleCharacters(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId3 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter1 = new Filter("/ext/id", "tenant*-*");
    final Filter filter2 = new Filter("/ext/value", "test$2*e");
    final Sort sortOption = new Sort("/id");
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(false).setExtensions(Map.of("id", "tenant1-id")), tenantId2, new Tenant().setEnabled(true).setExtensions(Map.of("id", "tenant2-id", "value", "test$2Value")), tenantId3, new Tenant().setEnabled(true).setExtensions(Map.of("id", "tenant3-id", "value", "test$3Value")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter1, filter2), List.of(sortOption), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<TenantWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(1);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo(tenantId2);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Filter(org.eclipse.hono.service.management.Filter) Truth.assertThat(com.google.common.truth.Truth.assertThat) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Sort(org.eclipse.hono.service.management.Sort) Adapter(org.eclipse.hono.util.Adapter) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Optional(java.util.Optional) NoopSpan(io.opentracing.noop.NoopSpan) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 12 with SearchResult

use of org.eclipse.hono.service.management.SearchResult in project hono by eclipse.

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithPageOffset.

/**
 * Verifies that a request to search tenants with valid page offset succeeds and the result is in accordance with
 * the specified page offset.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithPageOffset(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 1;
    final Filter filter = new Filter("/enabled", true);
    final Sort sortOption = new Sort("/ext/id");
    sortOption.setDirection(Sort.Direction.DESC);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(true).setExtensions(Map.of("id", "1")), tenantId2, new Tenant().setEnabled(true).setExtensions(Map.of("id", "2")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(sortOption), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<TenantWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo(tenantId1);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) Filter(org.eclipse.hono.service.management.Filter) Truth.assertThat(com.google.common.truth.Truth.assertThat) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) CompositeFuture(io.vertx.core.CompositeFuture) List(java.util.List) Sort(org.eclipse.hono.service.management.Sort) Adapter(org.eclipse.hono.util.Adapter) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Optional(java.util.Optional) NoopSpan(io.opentracing.noop.NoopSpan) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Aggregations

Future (io.vertx.core.Future)12 HttpURLConnection (java.net.HttpURLConnection)12 List (java.util.List)12 Optional (java.util.Optional)12 SearchResult (org.eclipse.hono.service.management.SearchResult)12 Filter (org.eclipse.hono.service.management.Filter)11 Sort (org.eclipse.hono.service.management.Sort)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)9 NoopSpan (io.opentracing.noop.NoopSpan)9 VertxTestContext (io.vertx.junit5.VertxTestContext)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 DeviceRegistryUtils (org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils)9 Test (org.junit.jupiter.api.Test)9 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)8 CompositeFuture (io.vertx.core.CompositeFuture)7 Adapter (org.eclipse.hono.util.Adapter)7 Tracer (io.opentracing.Tracer)3 Promise (io.vertx.core.Promise)3 JsonObject (io.vertx.core.json.JsonObject)3