Search in sources :

Example 46 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.

the class FuturesTest method testCreateGetsCompletedOnOriginalContext.

/**
 * Verifies that the Future returned by the <em>create</em> method
 * will be completed on the vert.x context it was invoked on.
 *
 * @param ctx The vert.x test context.
 * @param vertx The vert.x instance.
 */
@Test
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
public void testCreateGetsCompletedOnOriginalContext(final VertxTestContext ctx, final Vertx vertx) {
    final Context context = vertx.getOrCreateContext();
    context.runOnContext(v -> {
        LOG.trace("run on context");
        Futures.create(() -> CompletableFuture.runAsync(() -> {
            LOG.trace("run async");
        })).onComplete(r -> {
            LOG.trace("after run async");
            ctx.verify(() -> {
                assertTrue(r.succeeded());
                assertEquals(context, vertx.getOrCreateContext());
            });
            ctx.completeNow();
        });
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Context(io.vertx.core.Context) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 47 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.

the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDeviceViaGatewayGroup.

/**
 * Verifies that the registry succeeds a request to assert the registration status of a device that connects via a
 * gateway that is authorized through its group membership.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDeviceViaGatewayGroup(final VertxTestContext ctx) {
    final String gatewayId = getHelper().getRandomDeviceId(tenantId);
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    final Device device = new Device();
    device.setViaGroups(List.of("group"));
    final Device gateway = new Device();
    gateway.setMemberOf(List.of("group"));
    Future.succeededFuture().compose(ok -> getHelper().registry.registerDevice(tenantId, gatewayId, gateway)).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
        ctx.verify(() -> {
            assertThat(resp.getDeviceId()).isEqualTo(deviceId);
            assertThat(resp.getAuthorizedGateways()).containsExactly(gatewayId);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 48 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.

the class DeviceRegistrationApiTests method testAssertRegistrationFailsForDisabledGateway.

/**
 * Verifies that the registry fails a disabled gateway's request to assert a device's registration status with a 403
 * error code.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForDisabledGateway(final VertxTestContext ctx) {
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    final String gatewayId = getHelper().getRandomDeviceId(tenantId);
    final Device gateway = new Device();
    gateway.setEnabled(false);
    final Device device = new Device();
    device.setVia(Collections.singletonList(gatewayId));
    getHelper().registry.registerDevice(tenantId, gatewayId, gateway).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(r -> getClient().assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
        assertErrorCode(t, HttpURLConnection.HTTP_FORBIDDEN);
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 49 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.

the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDeviceViaGateway.

/**
 * Verifies that the registry succeeds a request to assert the registration status of a device that connects via an
 * authorized gateway.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDeviceViaGateway(final VertxTestContext ctx) {
    final String gatewayId = getHelper().getRandomDeviceId(tenantId);
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    final List<String> via = List.of(gatewayId, "another-gateway");
    final Device device = new Device();
    device.setVia(via);
    getHelper().registry.registerDevice(tenantId, gatewayId).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, gatewayId, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
        ctx.verify(() -> {
            assertThat(resp.getDeviceId()).isEqualTo(deviceId);
            assertThat(resp.getAuthorizedGateways()).containsExactlyElementsIn(via);
        });
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Device(org.eclipse.hono.service.management.device.Device) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) Future(io.vertx.core.Future) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) JsonObject(io.vertx.core.json.JsonObject) NoopSpan(io.opentracing.noop.NoopSpan) Collections(java.util.Collections) Device(org.eclipse.hono.service.management.device.Device) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 50 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project hono by eclipse.

the class TenantJmsIT method testGetTenantFailsForUnsupportedSearchCriteria.

/**
 * Verifies that a request to retrieve information for unsupported search criteria
 * fails with a 400 status.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testGetTenantFailsForUnsupportedSearchCriteria(final VertxTestContext ctx) {
    final JsonObject unsupportedSearchCriteria = new JsonObject().put("color", "blue");
    allTenantClient.get(unsupportedSearchCriteria.toBuffer()).onComplete(ctx.failing(t -> {
        ctx.verify(() -> assertThat(((ServiceInvocationException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_BAD_REQUEST));
        ctx.completeNow();
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) TenantConstants(org.eclipse.hono.util.TenantConstants) JmsBasedHonoConnection(org.eclipse.hono.tests.jms.JmsBasedHonoConnection) TenantClient(org.eclipse.hono.client.registry.TenantClient) Truth.assertThat(com.google.common.truth.Truth.assertThat) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) VertxExtension(io.vertx.junit5.VertxExtension) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) JmsBasedTenantClient(org.eclipse.hono.tests.jms.JmsBasedTenantClient) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Buffer(io.vertx.core.buffer.Buffer) BeforeAll(org.junit.jupiter.api.BeforeAll) JsonObject(io.vertx.core.json.JsonObject) Checkpoint(io.vertx.junit5.Checkpoint) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) JsonObject(io.vertx.core.json.JsonObject) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Aggregations

Timeout (io.vertx.junit5.Timeout)75 VertxTestContext (io.vertx.junit5.VertxTestContext)70 Test (org.junit.jupiter.api.Test)69 TimeUnit (java.util.concurrent.TimeUnit)64 Truth.assertThat (com.google.common.truth.Truth.assertThat)62 Future (io.vertx.core.Future)53 HttpURLConnection (java.net.HttpURLConnection)50 Handler (io.vertx.core.Handler)47 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)47 BeforeEach (org.junit.jupiter.api.BeforeEach)45 Buffer (io.vertx.core.buffer.Buffer)44 Promise (io.vertx.core.Promise)43 Vertx (io.vertx.core.Vertx)38 JsonObject (io.vertx.core.json.JsonObject)37 VertxExtension (io.vertx.junit5.VertxExtension)37 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 MethodSource (org.junit.jupiter.params.provider.MethodSource)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 Tenant (org.eclipse.hono.service.management.tenant.Tenant)33