Search in sources :

Example 11 with Filter

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

the class AbstractTenantManagementSearchTenantsTest method testSearchTenantsWhenNoTenantsAreFound.

/**
 * Verifies that a request to search tenants fails with a {@value HttpURLConnection#HTTP_NOT_FOUND}
 * when no matching tenants are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchTenantsWhenNoTenantsAreFound(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", false);
    createTenants(Map.of(tenantId, new Tenant().setEnabled(true))).onFailure(ctx::failNow).compose(ok -> getTenantManagementService().searchTenants(pageSize, pageOffset, List.of(filter), List.of(), NoopSpan.INSTANCE)).onComplete(ctx.failing(t -> {
        ctx.verify(() -> {
            assertThat(ServiceInvocationException.extractStatusCode(t)).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
        });
        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) Test(org.junit.jupiter.api.Test)

Example 12 with Filter

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

the class AbstractDeviceManagementSearchDevicesTest method testSearchDevicesWithPageSize.

/**
 * Verifies that a request to search devices with valid pageSize succeeds and the result is in accordance
 * with the specified page size.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchDevicesWithPageSize(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    createDevices(tenantId, Map.of("testDevice1", new Device().setEnabled(true), "testDevice2", new Device().setEnabled(true))).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);
            assertThat(s.getPayload().getTotal()).isEqualTo(2);
            assertThat(s.getPayload().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) 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) Test(org.junit.jupiter.api.Test)

Example 13 with Filter

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

the class AbstractDeviceManagementSearchDevicesTest method testSearchDevicesWithCardToMatchSingleCharacter.

/**
 * Verifies that a request to search devices with filters containing the wildcard character '?'
 * and matching devices are found.
 *
 * @param ctx The vert.x test context.
 */
@Test
default void testSearchDevicesWithCardToMatchSingleCharacter(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 10;
    final int pageOffset = 0;
    final Filter filter1 = new Filter("/id", "testDevice-?");
    final Filter filter2 = new Filter("/ext/value", "test$?Value");
    final Sort sortOption = new Sort("/id");
    createDevices(tenantId, Map.of("testDevice-x", new Device().setExtensions(Map.of("value", "test$Value")), "testDevice-1", new Device().setExtensions(Map.of("value", "test$1Value")), "testDevice-2", new Device().setExtensions(Map.of("value", "test$2Value")))).compose(ok -> getDeviceManagementService().searchDevices(tenantId, 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<DeviceWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(2);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo("testDevice-1");
            assertThat(searchResult.getResult().get(1).getId()).isEqualTo("testDevice-2");
        });
        ctx.completeNow();
    })));
}
Also used : Filter(org.eclipse.hono.service.management.Filter) Sort(org.eclipse.hono.service.management.Sort) Test(org.junit.jupiter.api.Test)

Example 14 with Filter

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

the class AbstractDeviceManagementSearchDevicesTest method testSearchDevicesWithSortOption.

/**
 * Verifies that a request to search devices 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 testSearchDevicesWithSortOption(final VertxTestContext ctx) {
    final String tenantId = DeviceRegistryUtils.getUniqueIdentifier();
    final int pageSize = 1;
    final int pageOffset = 0;
    final Filter filter = new Filter("/enabled", true);
    final Sort sortOption = new Sort("/ext/id");
    sortOption.setDirection(Sort.Direction.DESC);
    createDevices(tenantId, Map.of("testDevice1", new Device().setEnabled(true).setExtensions(Map.of("id", "aaa")), "testDevice2", new Device().setEnabled(true).setExtensions(Map.of("id", "bbb")))).compose(ok -> getDeviceManagementService().searchDevices(tenantId, 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<DeviceWithId> searchResult = s.getPayload();
            assertThat(searchResult.getTotal()).isEqualTo(2);
            assertThat(searchResult.getResult()).hasSize(1);
            assertThat(searchResult.getResult().get(0).getId()).isEqualTo("testDevice2");
        });
        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) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Test(org.junit.jupiter.api.Test)

Example 15 with Filter

use of org.eclipse.hono.service.management.Filter 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)

Aggregations

Filter (org.eclipse.hono.service.management.Filter)21 Sort (org.eclipse.hono.service.management.Sort)20 Future (io.vertx.core.Future)17 HttpURLConnection (java.net.HttpURLConnection)17 List (java.util.List)17 Optional (java.util.Optional)17 Test (org.junit.jupiter.api.Test)17 SearchResult (org.eclipse.hono.service.management.SearchResult)14 Truth.assertThat (com.google.common.truth.Truth.assertThat)13 NoopSpan (io.opentracing.noop.NoopSpan)12 VertxTestContext (io.vertx.junit5.VertxTestContext)12 Map (java.util.Map)12 DeviceRegistryUtils (org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils)12 CompositeFuture (io.vertx.core.CompositeFuture)10 Collectors (java.util.stream.Collectors)10 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)8 Adapter (org.eclipse.hono.util.Adapter)8 Span (io.opentracing.Span)5 JsonObject (io.vertx.core.json.JsonObject)5 RegistryManagementConstants (org.eclipse.hono.util.RegistryManagementConstants)5