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();
}));
}
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();
}));
}
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();
})));
}
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();
}));
}
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();
}));
}
Aggregations