Search in sources :

Example 21 with TestContext

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;
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Constants(org.eclipse.hono.util.Constants) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) TenantClient(org.eclipse.hono.client.TenantClient) Timeout(org.junit.rules.Timeout) HonoClient(org.eclipse.hono.client.HonoClient) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BeforeClass(org.junit.BeforeClass)

Example 22 with TestContext

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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) TestRule(org.junit.rules.TestRule) TenantConstants(org.eclipse.hono.util.TenantConstants) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Constants(org.eclipse.hono.util.Constants) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) JsonArray(io.vertx.core.json.JsonArray) Rule(org.junit.Rule) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) After(org.junit.After) DeviceRegistryHttpClient(org.eclipse.hono.tests.DeviceRegistryHttpClient) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 23 with TestContext

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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) TestRule(org.junit.rules.TestRule) TenantConstants(org.eclipse.hono.util.TenantConstants) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Constants(org.eclipse.hono.util.Constants) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) JsonArray(io.vertx.core.json.JsonArray) Rule(org.junit.Rule) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) After(org.junit.After) DeviceRegistryHttpClient(org.eclipse.hono.tests.DeviceRegistryHttpClient) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 24 with TestContext

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());
    }));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) TenantResult(org.eclipse.hono.util.TenantResult) BeforeClass(org.junit.BeforeClass) TenantConstants(org.eclipse.hono.util.TenantConstants) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) EventBusMessage(org.eclipse.hono.util.EventBusMessage) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Future(io.vertx.core.Future) JsonArray(io.vertx.core.json.JsonArray) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) EventBusMessage(org.eclipse.hono.util.EventBusMessage) JsonObject(io.vertx.core.json.JsonObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Example 25 with TestContext

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());
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) TenantResult(org.eclipse.hono.util.TenantResult) BeforeClass(org.junit.BeforeClass) TenantConstants(org.eclipse.hono.util.TenantConstants) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) EventBusMessage(org.eclipse.hono.util.EventBusMessage) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Future(io.vertx.core.Future) JsonArray(io.vertx.core.json.JsonArray) Timeout(org.junit.rules.Timeout) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) EventBusMessage(org.eclipse.hono.util.EventBusMessage) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.Test)

Aggregations

TestContext (io.vertx.ext.unit.TestContext)148 Test (org.junit.Test)147 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)141 RunWith (org.junit.runner.RunWith)141 Async (io.vertx.ext.unit.Async)123 Future (io.vertx.core.Future)121 Handler (io.vertx.core.Handler)112 Vertx (io.vertx.core.Vertx)103 HttpURLConnection (java.net.HttpURLConnection)100 Before (org.junit.Before)97 Timeout (org.junit.rules.Timeout)95 JsonObject (io.vertx.core.json.JsonObject)91 Rule (org.junit.Rule)83 Mockito (org.mockito.Mockito)74 Constants (org.eclipse.hono.util.Constants)68 Assert.assertThat (org.junit.Assert.assertThat)62 Context (io.vertx.core.Context)57 CoreMatchers.is (org.hamcrest.CoreMatchers.is)54 AsyncResult (io.vertx.core.AsyncResult)53 Buffer (io.vertx.core.buffer.Buffer)52