use of org.eclipse.hono.util.DataVolume 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();
}));
}
Aggregations