Search in sources :

Example 31 with TIMEOUT

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

the class DeviceRegistrationApiTests method testAssertRegistrationFailsForDisabledDevice.

/**
 * Verifies that the registry fails to assert a disabled device's registration status with a 404 error code.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForDisabledDevice(final VertxTestContext ctx) {
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    final Device device = new Device();
    device.setEnabled(false);
    getHelper().registry.registerDevice(tenantId, deviceId, device).compose(ok -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.failing(t -> {
        ctx.verify(() -> assertErrorCode(t, HttpURLConnection.HTTP_NOT_FOUND));
        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 32 with TIMEOUT

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

the class DeviceRegistrationApiTests method testAssertRegistrationSucceedsForDevice.

/**
 * Verifies that the registry succeeds a request to assert a device's registration status.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationSucceedsForDevice(final VertxTestContext ctx) {
    final JsonObject defaults = new JsonObject().put(MessageHelper.SYS_PROPERTY_CONTENT_TYPE, "application/vnd.acme+json");
    final Device device = new Device();
    device.setDefaults(defaults.getMap());
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    getHelper().registry.registerDevice(tenantId, deviceId, device).compose(r -> getClient().assertRegistration(tenantId, deviceId, null, NoopSpan.INSTANCE.context())).onComplete(ctx.succeeding(resp -> {
        ctx.verify(() -> {
            assertThat(resp.getDeviceId()).isEqualTo(deviceId);
            assertThat(resp.getDefaults()).containsExactlyEntriesIn(defaults.getMap());
        });
        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) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 33 with TIMEOUT

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

the class DeviceRegistrationApiTests method testAssertRegistrationFailsForUnauthorizedGateway.

/**
 * Verifies that the registry fails a gateway's request to assert a device's registration status for which it is not
 * authorized with a 403 error code.
 *
 * @param ctx The vert.x test context.
 */
@Timeout(value = 5, timeUnit = TimeUnit.SECONDS)
@Test
public void testAssertRegistrationFailsForUnauthorizedGateway(final VertxTestContext ctx) {
    // Prepare the identities to insert
    final String deviceId = getHelper().getRandomDeviceId(tenantId);
    final String authorizedGateway = getHelper().getRandomDeviceId(tenantId);
    final String unauthorizedGateway = getHelper().getRandomDeviceId(tenantId);
    final Device device = new Device();
    device.setVia(Collections.singletonList(authorizedGateway));
    getHelper().registry.registerDevice(tenantId, authorizedGateway).compose(ok -> getHelper().registry.registerDevice(tenantId, unauthorizedGateway)).compose(ok -> getHelper().registry.registerDevice(tenantId, deviceId, device)).compose(ok -> getClient().assertRegistration(tenantId, deviceId, unauthorizedGateway, 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 34 with TIMEOUT

use of org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT in project vertx-web by vert-x3.

the class RouterBuilderIntegrationTest method testIssue1876.

@Timeout(10000)
@Test
public void testIssue1876(Vertx vertx, VertxTestContext testContext) {
    Checkpoint checkpoint = testContext.checkpoint(2);
    loadBuilderAndStartServer(vertx, "specs/repro_1876.yaml", testContext, routerBuilder -> {
        routerBuilder.setOptions(new RouterBuilderOptions().setRequireSecurityHandlers(false).setMountNotImplementedHandler(true));
        routerBuilder.operation("createAccount").handler(routingContext -> routingContext.response().setStatusCode(200).end());
        routerBuilder.operation("createAccountMember").handler(routingContext -> routingContext.response().setStatusCode(200).end());
    }).onComplete(h -> {
        testRequest(client, HttpMethod.POST, "/accounts").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("id", 123).put("type", "account-registration").put("attributes", new JsonObject().put("ownerEmail", "test@gmail.com"))), testContext, checkpoint);
        testRequest(client, HttpMethod.POST, "/members").expect(statusCode(200), emptyResponse()).sendJson(new JsonObject().put("data", new JsonObject().put("type", "account-member-registration").put("attributes", new JsonObject().put("email", "test@gmail.com"))), testContext, checkpoint);
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Arrays(java.util.Arrays) RequestParameters(io.vertx.ext.web.validation.RequestParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiMap(io.vertx.core.MultiMap) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) BodyProcessorException(io.vertx.ext.web.validation.BodyProcessorException) Timeout(io.vertx.junit5.Timeout) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MultipartForm(io.vertx.ext.web.multipart.MultipartForm) ParameterLocation(io.vertx.ext.web.validation.impl.ParameterLocation) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonObject(io.vertx.core.json.JsonObject) RequestParameter(io.vertx.ext.web.validation.RequestParameter) Route(io.vertx.ext.web.Route) QueryStringEncoder(io.netty.handler.codec.http.QueryStringEncoder) StaticHandler(io.vertx.ext.web.handler.StaticHandler) Vertx(io.vertx.core.Vertx) TestRequest(io.vertx.ext.web.validation.testutils.TestRequest) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Stream(java.util.stream.Stream) ValidationTestUtils(io.vertx.ext.web.validation.testutils.ValidationTestUtils) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) ParameterProcessorException(io.vertx.ext.web.validation.ParameterProcessorException) Condition(org.assertj.core.api.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Pattern(java.util.regex.Pattern) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 35 with TIMEOUT

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

the class RequestResponseClientTest method testCreateAndSendRequestReturnsCorrespondingResponseMessage.

/**
 * Verifies that the client returns the service's response message that correlates with the request.
 *
 * @param ctx The vert.x test context.
 */
@Test
public void testCreateAndSendRequestReturnsCorrespondingResponseMessage(final VertxTestContext ctx) {
    // WHEN sending a request message to the peer
    client.compose(c -> c.createAndSendRequest("request", null, Buffer.buffer("hello"), "text/plain", SimpleRequestResponseResult::from, span)).onComplete(ctx.succeeding(s -> {
        ctx.verify(() -> {
            // THEN the response is passed to the handler registered with the request
            assertEquals(200, s.getStatus());
            assertEquals("payload", s.getPayload().toString());
            verify(sample).completed(isA(Accepted.class));
            // and a timer has been set to time out the request
            final ArgumentCaptor<Handler<Long>> timeoutHandlerCaptor = VertxMockSupport.argumentCaptorHandler();
            verify(vertx).setTimer(eq(clientConfig.getRequestTimeout()), timeoutHandlerCaptor.capture());
            // triggering the timer now that the request has been handled should not invoke the sampler timeout method
            timeoutHandlerCaptor.getValue().handle(1L);
            verify(sample, never()).timeout();
        });
        ctx.completeNow();
    }));
    // WHEN a response is received for the request
    final Message request = verifySenderSendAndUpdateDelivery(new Accepted());
    final ProtonMessageHandler responseHandler = verifyResponseHandlerSet();
    final Message response = ProtonHelper.message("payload");
    response.setCorrelationId(request.getMessageId());
    MessageHelper.addProperty(response, MessageHelper.APP_PROPERTY_STATUS, 200);
    final ProtonDelivery delivery = mock(ProtonDelivery.class);
    responseHandler.handle(delivery, response);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ProtonReceiver(io.vertx.proton.ProtonReceiver) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Timeout(io.vertx.junit5.Timeout) EventBus(io.vertx.core.eventbus.EventBus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Map(java.util.Map) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) TracingMockSupport(org.eclipse.hono.test.TracingMockSupport) JsonObject(io.vertx.core.json.JsonObject) AmqpError(org.apache.qpid.proton.amqp.transport.AmqpError) Data(org.apache.qpid.proton.amqp.messaging.Data) ProtonQoS(io.vertx.proton.ProtonQoS) MessageHelper(org.eclipse.hono.util.MessageHelper) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) Buffer(io.vertx.core.buffer.Buffer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) Span(io.opentracing.Span) ProtonSender(io.vertx.proton.ProtonSender) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ProtonDelivery(io.vertx.proton.ProtonDelivery) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) AmqpClientUnitTestHelper(org.eclipse.hono.client.amqp.test.AmqpClientUnitTestHelper) ClientErrorException(org.eclipse.hono.client.ClientErrorException) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) ArgumentCaptor(org.mockito.ArgumentCaptor) Symbol(org.apache.qpid.proton.amqp.Symbol) Message(org.apache.qpid.proton.message.Message) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HonoConnection(org.eclipse.hono.client.HonoConnection) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) Tracer(io.opentracing.Tracer) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) ProtonHelper(io.vertx.proton.ProtonHelper) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) ResourceLimitExceededException(org.eclipse.hono.client.ResourceLimitExceededException) SendMessageSampler(org.eclipse.hono.client.SendMessageSampler) Handler(io.vertx.core.Handler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentCaptor(org.mockito.ArgumentCaptor) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Message(org.apache.qpid.proton.message.Message) ProtonDelivery(io.vertx.proton.ProtonDelivery) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) Test(org.junit.jupiter.api.Test)

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