use of org.eclipse.hono.service.management.tenant.TenantManagementService in project hono by eclipse.
the class MongoDbBasedTenantServiceTest method testGetTenantByAliasSucceedsForExistingTenant.
/**
* Verifies that a tenant can be looked up by its alias using the {@link TenantManagementService} API.
*
* @param ctx The vert.x test context.
*/
@Test
public void testGetTenantByAliasSucceedsForExistingTenant(final VertxTestContext ctx) {
final Tenant tenantSpec = new Tenant().setAlias("the-alias");
// GIVEN a tenant that has been added via the Management API
addTenant("tenant", tenantSpec).compose(ok -> {
ctx.verify(() -> {
assertEquals(HttpURLConnection.HTTP_CREATED, ok.getStatus());
});
// WHEN retrieving the tenant by alias using the Tenant API
return getTenantService().get("the-alias", NoopSpan.INSTANCE);
}).onComplete(ctx.succeeding(tenantResult -> {
ctx.verify(() -> {
// THEN the tenant is found
assertThat(tenantResult.isOk()).isTrue();
// and the response can be cached
assertThat(tenantResult.getCacheDirective()).isNotNull();
assertThat(tenantResult.getCacheDirective().isCachingAllowed()).isTrue();
assertThat(tenantResult.getPayload().getString(RegistryManagementConstants.FIELD_PAYLOAD_TENANT_ID)).isEqualTo("tenant");
});
ctx.completeNow();
}));
}
Aggregations