Search in sources :

Example 1 with ResourceLimitsPeriod

use of org.eclipse.hono.util.ResourceLimitsPeriod in project hono by eclipse.

the class TenantApiTests method testGetTenant.

/**
 * Verifies that an existing tenant can be retrieved.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetTenant(final VertxTestContext ctx) {
    final JsonObject defaults = new JsonObject().put("ttl", 30);
    final Map<String, Object> httpAdapterExtensions = Map.of("deployment", Map.of("maxInstances", 4));
    final ResourceLimits resourceLimits = new ResourceLimits().setMaxConnections(100000).setMaxTtl(30L).setDataVolume(new DataVolume(Instant.parse("2019-07-27T14:30:00Z"), new ResourceLimitsPeriod(PeriodMode.days).setNoOfDays(30), 2147483648L));
    final String tenantId = getHelper().getRandomTenantId();
    final Tenant tenant = new Tenant();
    tenant.setEnabled(true);
    tenant.setResourceLimits(resourceLimits);
    tenant.setDefaults(defaults.getMap());
    tenant.putExtension("customer", "ACME Inc.");
    tenant.addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(true).setDeviceAuthenticationRequired(false)).addAdapterConfig(new Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(true).setDeviceAuthenticationRequired(true).setExtensions(httpAdapterExtensions));
    // expected tenant object
    final TenantObject expectedTenantObject = TenantObject.from(tenantId, true).setDefaults(defaults).setResourceLimits(resourceLimits).addAdapter(new org.eclipse.hono.util.Adapter(Constants.PROTOCOL_ADAPTER_TYPE_MQTT).setEnabled(Boolean.TRUE).setDeviceAuthenticationRequired(Boolean.FALSE)).addAdapter(new org.eclipse.hono.util.Adapter(Constants.PROTOCOL_ADAPTER_TYPE_HTTP).setEnabled(Boolean.TRUE).setDeviceAuthenticationRequired(Boolean.TRUE).setExtensions(httpAdapterExtensions));
    getHelper().registry.addTenant(tenantId, tenant).compose(ok -> getAdminClient().get(tenantId, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(tenantObject -> {
        ctx.verify(() -> {
            assertThat(tenantObject.getDefaults()).isEqualTo(expectedTenantObject.getDefaults());
            Assertions.assertThat(tenantObject.getAdapters()).usingRecursiveFieldByFieldElementComparator().containsAll(expectedTenantObject.getAdapters());
            assertThat(tenantObject.getResourceLimits().getMaxConnections()).isEqualTo(expectedTenantObject.getResourceLimits().getMaxConnections());
            assertThat(tenantObject.getResourceLimits().getMaxTtl()).isEqualTo(expectedTenantObject.getResourceLimits().getMaxTtl());
            assertThat(tenantObject.getResourceLimits().getDataVolume().getMaxBytes()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getMaxBytes());
            assertThat(tenantObject.getResourceLimits().getDataVolume().getEffectiveSince()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getEffectiveSince());
            assertThat(tenantObject.getResourceLimits().getDataVolume().getPeriod().getMode()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getPeriod().getMode());
            assertThat(tenantObject.getResourceLimits().getDataVolume().getPeriod().getNoOfDays()).isEqualTo(expectedTenantObject.getResourceLimits().getDataVolume().getPeriod().getNoOfDays());
            final JsonObject extensions = tenantObject.getProperty("ext", JsonObject.class);
            assertThat(extensions.getString("customer")).isEqualTo("ACME Inc.");
            // implicitly added by DeviceRegistryHttpClient
            assertThat(extensions.getString(TenantConstants.FIELD_EXT_MESSAGING_TYPE)).isEqualTo(IntegrationTestSupport.getConfiguredMessagingType().name());
        });
        ctx.completeNow();
    }));
}
Also used : DataVolume(org.eclipse.hono.util.DataVolume) HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) KeyPair(java.security.KeyPair) X500Principal(javax.security.auth.x500.X500Principal) TenantConstants(org.eclipse.hono.util.TenantConstants) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) Map(java.util.Map) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions(org.assertj.core.api.Assertions) JsonObject(io.vertx.core.json.JsonObject) Tenants(org.eclipse.hono.tests.Tenants) KeyPairGenerator(java.security.KeyPairGenerator) ResourceLimits(org.eclipse.hono.util.ResourceLimits) PublicKey(java.security.PublicKey) TenantClient(org.eclipse.hono.client.registry.TenantClient) Truth.assertThat(com.google.common.truth.Truth.assertThat) Instant(java.time.Instant) PeriodMode(org.eclipse.hono.util.ResourceLimitsPeriod.PeriodMode) ResourceLimitsPeriod(org.eclipse.hono.util.ResourceLimitsPeriod) TenantObject(org.eclipse.hono.util.TenantObject) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Adapter(org.eclipse.hono.util.Adapter) DataVolume(org.eclipse.hono.util.DataVolume) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoopSpan(io.opentracing.noop.NoopSpan) TrustAnchor(java.security.cert.TrustAnchor) JsonObject(io.vertx.core.json.JsonObject) Adapter(org.eclipse.hono.util.Adapter) TenantObject(org.eclipse.hono.util.TenantObject) Tenant(org.eclipse.hono.service.management.tenant.Tenant) ResourceLimitsPeriod(org.eclipse.hono.util.ResourceLimitsPeriod) ResourceLimits(org.eclipse.hono.util.ResourceLimits) JsonObject(io.vertx.core.json.JsonObject) TenantObject(org.eclipse.hono.util.TenantObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 NoopSpan (io.opentracing.noop.NoopSpan)1 JsonObject (io.vertx.core.json.JsonObject)1 Timeout (io.vertx.junit5.Timeout)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 HttpURLConnection (java.net.HttpURLConnection)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 TrustAnchor (java.security.cert.TrustAnchor)1 Instant (java.time.Instant)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 X500Principal (javax.security.auth.x500.X500Principal)1 Assertions (org.assertj.core.api.Assertions)1 TenantClient (org.eclipse.hono.client.registry.TenantClient)1 Tenant (org.eclipse.hono.service.management.tenant.Tenant)1 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)1 Tenants (org.eclipse.hono.tests.Tenants)1