Search in sources :

Example 1 with SearchResult

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

the class AbstractDeviceManagementSearchDevicesTest method testSearchDevicesWithAFilterSucceeds.

/**
 * Verifies that a request to search devices with a valid filter succeeds and matching devices are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchDevicesWithAFilterSucceeds(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    createDevices(tenantId, Map.of("testDevice1", new Device().setEnabled(true), "testDevice2", new Device().setEnabled(false))).compose(ok -> getDeviceManagementService().searchDevices(tenantId, pageSize, pageOffset, List.of(filter), List.of(), NoopSpan.INSTANCE)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            assertThat(s.getStatus()).isEqualTo(HttpURLConnection.HTTP_OK);
            final SearchResult<DeviceWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo("testDevice1");
        });
        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) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Optional(java.util.Optional) Assertions(org.eclipse.hono.deviceregistry.util.Assertions) NoopSpan(io.opentracing.noop.NoopSpan) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Filter(org.eclipse.hono.service.management.Filter) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 2 with SearchResult

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

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithAValidFilterSucceeds.

/**
 * Verifies that a request to search tenants with a valid filter succeeds and matching tenants are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithAValidFilterSucceeds(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(true), tenantId2, new Tenant().setEnabled(false))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(), 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().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) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 3 with SearchResult

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

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithPageSize.

/**
 * Verifies that a request to search tenants with a valid pageSize succeeds and the result is in accordance
 * with the specified page size.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithPageSize(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(true), tenantId2, new Tenant().setEnabled(true))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(), 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);
        });
        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) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 4 with SearchResult

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

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithMultipleFiltersSucceeds.

/**
 * Verifies that a request to search tenants with multiple filters succeeds and matching tenants are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithMultipleFiltersSucceeds(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter1 = new Filter("/enabled", true);
    final Filter filter2 = new Filter("/adapters/0/type", "MQTT");
    final Filter filter3 = new Filter("/ext/group", "A");
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(true).setExtensions(Map.of("group", "A")), tenantId2, new Tenant().setEnabled(true).addAdapterConfig(new Adapter("MQTT")).setExtensions(Map.of("group", "A")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter1, filter2, filter3), List.of(), 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) Adapter(org.eclipse.hono.util.Adapter) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 5 with SearchResult

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

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWithSortOptions.

/**
 * Verifies that a request to search tenants with a sort option succeeds and the result is in accordance with the
 * specified sort option.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWithSortOptions(final VertxTestContext ctx) {
    final String tenantId1 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId2 = DeviceRegistryUtils.getUniqueIdentifier();
    final String tenantId3 = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    final Sort sortOption1 = new Sort("/ext/group");
    final Sort sortOption2 = new Sort("/ext/id");
    sortOption1.setDirection(Sort.Direction.DESC);
    sortOption2.setDirection(Sort.Direction.ASC);
    createTenants(Map.of(tenantId1, new Tenant().setEnabled(false).setExtensions(Map.of("id", "1", "group", "B")), tenantId2, new Tenant().setEnabled(true).setExtensions(Map.of("id", "2", "group", "B")), tenantId3, new Tenant().setEnabled(true).setExtensions(Map.of("id", "3", "group", "B")))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(sortOption1, sortOption2), 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(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)

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