Search in sources :

Example 1 with TenantManagementService

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();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) AbstractTenantServiceTest(org.eclipse.hono.service.tenant.AbstractTenantServiceTest) BeforeEach(org.junit.jupiter.api.BeforeEach) LoggerFactory(org.slf4j.LoggerFactory) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) AfterAll(org.junit.jupiter.api.AfterAll) TestInstance(org.junit.jupiter.api.TestInstance) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) TenantManagementService(org.eclipse.hono.service.management.tenant.TenantManagementService) TenantService(org.eclipse.hono.service.tenant.TenantService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) MongoDbBasedTenantsConfigProperties(org.eclipse.hono.deviceregistry.mongodb.config.MongoDbBasedTenantsConfigProperties) AfterEach(org.junit.jupiter.api.AfterEach) Optional(java.util.Optional) Assertions(org.eclipse.hono.deviceregistry.util.Assertions) NoopSpan(io.opentracing.noop.NoopSpan) MongoDbBasedTenantDao(org.eclipse.hono.deviceregistry.mongodb.model.MongoDbBasedTenantDao) Tenant(org.eclipse.hono.service.management.tenant.Tenant) AbstractTenantServiceTest(org.eclipse.hono.service.tenant.AbstractTenantServiceTest) Test(org.junit.jupiter.api.Test)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 NoopSpan (io.opentracing.noop.NoopSpan)1 Promise (io.vertx.core.Promise)1 Vertx (io.vertx.core.Vertx)1 Timeout (io.vertx.junit5.Timeout)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 HttpURLConnection (java.net.HttpURLConnection)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1 MongoDbBasedTenantsConfigProperties (org.eclipse.hono.deviceregistry.mongodb.config.MongoDbBasedTenantsConfigProperties)1 MongoDbBasedTenantDao (org.eclipse.hono.deviceregistry.mongodb.model.MongoDbBasedTenantDao)1 Assertions (org.eclipse.hono.deviceregistry.util.Assertions)1 Tenant (org.eclipse.hono.service.management.tenant.Tenant)1 TenantManagementService (org.eclipse.hono.service.management.tenant.TenantManagementService)1 AbstractTenantServiceTest (org.eclipse.hono.service.tenant.AbstractTenantServiceTest)1 TenantService (org.eclipse.hono.service.tenant.TenantService)1 RegistryManagementConstants (org.eclipse.hono.util.RegistryManagementConstants)1 AfterAll (org.junit.jupiter.api.AfterAll)1 AfterEach (org.junit.jupiter.api.AfterEach)1