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