use of io.vertx.ext.unit.TestContext in project hono by eclipse.
the class TenantAmqpIT method prepareDeviceRegistry.
/**
* Starts the device registry, connects a client and provides a tenant API client.
*
* @param ctx The vert.x test context.
*/
@BeforeClass
public static void prepareDeviceRegistry(final TestContext ctx) {
client = DeviceRegistryAmqpTestSupport.prepareDeviceRegistryClient(vertx);
client.connect(new ProtonClientOptions()).compose(c -> c.getOrCreateTenantClient()).setHandler(ctx.asyncAssertSuccess(r -> {
tenantClient = r;
}));
}
use of io.vertx.ext.unit.TestContext in project hono by eclipse.
the class TenantHttpIT method testGetAddedTenant.
/**
* Verifies that a correctly added tenant record can be successfully looked up again.
*
* @param context The vert.x test context.
*/
@Test
public void testGetAddedTenant(final TestContext context) {
final JsonObject requestBody = buildTenantPayload(tenantId);
registry.addTenant(requestBody).compose(ar -> registry.getTenant(tenantId)).compose(b -> {
context.assertTrue(IntegrationTestSupport.testJsonObjectToBeContained(b.toJsonObject(), requestBody));
return Future.succeededFuture();
}).setHandler(context.asyncAssertSuccess());
}
use of io.vertx.ext.unit.TestContext in project hono by eclipse.
the class TenantHttpIT method testAddTenantRejectsDuplicateRegistration.
/**
* Verifies that a correctly filled JSON payload to add a tenant for an already existing record is
* responded with {@link HttpURLConnection#HTTP_CONFLICT} and a non empty error response message.
*
* @param context The vert.x test context.
*/
@Test
public void testAddTenantRejectsDuplicateRegistration(final TestContext context) {
final JsonObject payload = buildTenantPayload(tenantId);
registry.addTenant(payload).compose(ar -> {
// now try to add the tenant again
return registry.addTenant(payload, HttpURLConnection.HTTP_CONFLICT);
}).setHandler(context.asyncAssertSuccess());
}
use of io.vertx.ext.unit.TestContext in project hono by eclipse.
the class BaseTenantServiceTest method testAddFailsForEmptyAdapterArray.
/**
* Verifies that the base service fails for a payload that defines an empty adapter array (must be null or has to
* contain at least one element).
*
* @param ctx The vert.x test context.
*/
@Test
public void testAddFailsForEmptyAdapterArray(final TestContext ctx) {
final JsonObject testPayload = createValidTenantPayload();
testPayload.put(TenantConstants.FIELD_ADAPTERS, new JsonArray());
final EventBusMessage msg = createRequest(TenantConstants.TenantAction.add, testPayload);
tenantService.processRequest(msg).setHandler(ctx.asyncAssertFailure(t -> {
ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
}));
}
use of io.vertx.ext.unit.TestContext in project hono by eclipse.
the class BaseTenantServiceTest method testAddFailsForIncompleteMessage.
/**
* Verifies that the base service fails for an incomplete message that does not contain mandatory fields.
*
* @param ctx The vert.x test context.
*/
@Test
public void testAddFailsForIncompleteMessage(final TestContext ctx) {
final EventBusMessage msg = EventBusMessage.forOperation(TenantConstants.TenantAction.add.toString());
tenantService.processRequest(msg).setHandler(ctx.asyncAssertFailure(t -> {
ctx.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, ((ServiceInvocationException) t).getErrorCode());
}));
}
Aggregations