use of io.vertx.ext.unit.Async in project hono by eclipse.
the class HttpTestBase method testUploadMessageFailsForDisabledTenant.
/**
* Verifies that the HTTP adapter rejects messages from a device
* that belongs to a tenant for which the HTTP adapter has been disabled.
*
* @param ctx The test context
*/
@Test
public void testUploadMessageFailsForDisabledTenant(final TestContext ctx) {
// GIVEN a tenant for which the HTTP adapter is disabled
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final JsonObject adapterDetailsHttp = new JsonObject().put(TenantConstants.FIELD_ADAPTERS_TYPE, Constants.PROTOCOL_ADAPTER_TYPE_HTTP).put(TenantConstants.FIELD_ENABLED, Boolean.FALSE);
final TenantObject tenant = TenantObject.from(tenantId, true);
tenant.addAdapterConfiguration(adapterDetailsHttp);
final Async setup = ctx.async();
helper.registry.addTenant(JsonObject.mapFrom(tenant)).compose(ok -> helper.registry.registerDevice(tenantId, deviceId)).setHandler(ctx.asyncAssertSuccess(ok -> setup.complete()));
setup.await();
// WHEN a device that belongs to the tenant uploads a message
send(tenantId, deviceId, Buffer.buffer("hello")).setHandler(ctx.asyncAssertFailure(t -> {
// THEN the message gets rejected by the HTTP adapter
ctx.assertEquals(HttpURLConnection.HTTP_FORBIDDEN, ((ServiceInvocationException) t).getErrorCode());
}));
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class CredentialsHttpIT method removeCredentials.
/**
* Removes the credentials that have been added by the test.
*
* @param ctx The vert.x test context.
*/
@After
public void removeCredentials(final TestContext ctx) {
final Async deletion = ctx.async();
registry.removeAllCredentials(TENANT, deviceId, HttpURLConnection.HTTP_NO_CONTENT).setHandler(attempt -> deletion.complete());
deletion.await();
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class DeviceRegistrationHttpIT method removeDevice.
/**
* Removes the device that has been added by the test.
*
* @param ctx The vert.x test context.
*/
@After
public void removeDevice(final TestContext ctx) {
final Async deletion = ctx.async();
registry.deregisterDevice(TENANT, deviceId).setHandler(attempt -> deletion.complete());
deletion.await();
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class TenantHttpIT method removeTenant.
/**
* Removes the credentials that have been added by the test.
*
* @param ctx The vert.x test context.
*/
@After
public void removeTenant(final TestContext ctx) {
final Async deletion = ctx.async();
registry.removeTenant(tenantId, HttpURLConnection.HTTP_NO_CONTENT).setHandler(attempt -> deletion.complete());
deletion.await();
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class FileBasedCredentialsServiceTest method testGetCredentialsSucceedsForExistingCredentials.
/**
* Verifies that the service returns existing credentials.
*
* @param ctx The vert.x test context.
*/
@Test
public void testGetCredentialsSucceedsForExistingCredentials(final TestContext ctx) {
register(svc, "tenant", "device", "myId", "myType", new JsonArray(), ctx);
final Async get = ctx.async();
svc.get("tenant", "myType", "myId", ctx.asyncAssertSuccess(s -> {
assertThat(s.getStatus(), is(HttpURLConnection.HTTP_OK));
assertThat(s.getPayload().getString(CredentialsConstants.FIELD_AUTH_ID), is("myId"));
assertThat(s.getPayload().getString(CredentialsConstants.FIELD_TYPE), is("myType"));
get.complete();
}));
get.await(2000);
}
Aggregations