Search in sources :

Example 41 with HttpServer

use of io.vertx.core.http.HttpServer in project java-chassis by ServiceComb.

the class MockForRestServerVerticle method mockRestServerVerticle.

public void mockRestServerVerticle() {
    final HttpServer server = Mockito.mock(HttpServer.class);
    new MockUp<RestServerVerticle>() {

        @Mock
        private void startListen(HttpServer server, IpPort ipPort, Future<Void> startFuture) {
        }

        @Mock
        private HttpServer createHttpServer(boolean isHttp_2) {
            return server;
        }
    };
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Future(io.vertx.core.Future) MockUp(mockit.MockUp) IpPort(io.servicecomb.foundation.common.net.IpPort)

Example 42 with HttpServer

use of io.vertx.core.http.HttpServer in project hono by eclipse.

the class AbstractVertxBasedHttpProtocolAdapterTest method testStartUsesClientProvidedHttpServer.

/**
 * Verifies that a client provided HTTP server is started instead of creating and starting a new http server.
 *
 * @param ctx The helper to use for running async tests on vertx.
 */
@SuppressWarnings("unchecked")
@Test
public void testStartUsesClientProvidedHttpServer(final TestContext ctx) {
    // GIVEN an adapter with a client provided HTTP server
    final HttpServer server = getHttpServer(false);
    final AbstractVertxBasedHttpProtocolAdapter<HttpProtocolAdapterProperties> adapter = getAdapter(server, null);
    adapter.setCredentialsAuthProvider(credentialsAuthProvider);
    // WHEN starting the adapter
    final Async startup = ctx.async();
    Future<Void> startupTracker = Future.future();
    startupTracker.setHandler(ctx.asyncAssertSuccess(s -> {
        startup.complete();
    }));
    adapter.start(startupTracker);
    // THEN the client provided HTTP server has been configured and started
    startup.await();
    verify(server).requestHandler(any(Handler.class));
    verify(server).listen(any(Handler.class));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArgumentMatchers(org.mockito.ArgumentMatchers) ProtonDelivery(io.vertx.proton.ProtonDelivery) TenantConstants(org.eclipse.hono.util.TenantConstants) HttpServer(io.vertx.core.http.HttpServer) RunWith(org.junit.runner.RunWith) Router(io.vertx.ext.web.Router) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RoutingContext(io.vertx.ext.web.RoutingContext) TenantClient(org.eclipse.hono.client.TenantClient) MessageSender(org.eclipse.hono.client.MessageSender) Timeout(org.junit.rules.Timeout) Message(org.apache.qpid.proton.message.Message) RegistrationClient(org.eclipse.hono.client.RegistrationClient) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HonoClient(org.eclipse.hono.client.HonoClient) Before(org.junit.Before) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) Mockito(org.mockito.Mockito) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Handler(io.vertx.core.Handler) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) Handler(io.vertx.core.Handler) Test(org.junit.Test)

Example 43 with HttpServer

use of io.vertx.core.http.HttpServer in project hono by eclipse.

the class AbstractVertxBasedHttpProtocolAdapterTest method testStartDoesNotInvokeOnStartupSuccessIfStartupFails.

/**
 * Verifies that the <me>onStartupSuccess</em> method is not invoked if a client provided http server fails to start.
 *
 * @param ctx The helper to use for running async tests on vertx.
 */
@Test
public void testStartDoesNotInvokeOnStartupSuccessIfStartupFails(final TestContext ctx) {
    // GIVEN an adapter with a client provided http server that fails to bind to a socket when started
    HttpServer server = getHttpServer(true);
    AbstractVertxBasedHttpProtocolAdapter<HttpProtocolAdapterProperties> adapter = getAdapter(server, s -> ctx.fail("should not invoke onStartupSuccess"));
    // WHEN starting the adapter
    Future<Void> startupTracker = Future.future();
    startupTracker.setHandler(ctx.asyncAssertFailure());
    adapter.start(startupTracker);
// THEN the onStartupSuccess method has not been invoked
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Test(org.junit.Test)

Example 44 with HttpServer

use of io.vertx.core.http.HttpServer in project hono by eclipse.

the class AbstractVertxBasedHttpProtocolAdapterTest method testStartInvokesOnStartupSuccess.

/**
 * Verifies that the <me>onStartupSuccess</em> method is invoked if the http server has been started successfully.
 *
 * @param ctx The helper to use for running async tests on vertx.
 */
@Test
public void testStartInvokesOnStartupSuccess(final TestContext ctx) {
    // GIVEN an adapter with a client provided http server
    HttpServer server = getHttpServer(false);
    Async onStartupSuccess = ctx.async();
    AbstractVertxBasedHttpProtocolAdapter<HttpProtocolAdapterProperties> adapter = getAdapter(server, s -> onStartupSuccess.complete());
    adapter.setCredentialsAuthProvider(credentialsAuthProvider);
    adapter.setMetrics(mock(HttpAdapterMetrics.class));
    // WHEN starting the adapter
    Async startup = ctx.async();
    Future<Void> startupTracker = Future.future();
    startupTracker.setHandler(ctx.asyncAssertSuccess(s -> {
        startup.complete();
    }));
    adapter.start(startupTracker);
    // THEN the onStartupSuccess method has been invoked
    startup.await();
    onStartupSuccess.await();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArgumentMatchers(org.mockito.ArgumentMatchers) ProtonDelivery(io.vertx.proton.ProtonDelivery) TenantConstants(org.eclipse.hono.util.TenantConstants) HttpServer(io.vertx.core.http.HttpServer) RunWith(org.junit.runner.RunWith) Router(io.vertx.ext.web.Router) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RoutingContext(io.vertx.ext.web.RoutingContext) TenantClient(org.eclipse.hono.client.TenantClient) MessageSender(org.eclipse.hono.client.MessageSender) Timeout(org.junit.rules.Timeout) Message(org.apache.qpid.proton.message.Message) RegistrationClient(org.eclipse.hono.client.RegistrationClient) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HonoClient(org.eclipse.hono.client.HonoClient) Before(org.junit.Before) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) Mockito(org.mockito.Mockito) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Handler(io.vertx.core.Handler) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) Test(org.junit.Test)

Example 45 with HttpServer

use of io.vertx.core.http.HttpServer in project hono by eclipse.

the class AbstractVertxBasedHttpProtocolAdapterTest method testStartUpFailsIfCredentialsAuthProviderIsNotSet.

/**
 * Verifies that the <me>onStartupSuccess</em> method is not invoked if no credentials authentication provider is set.
 *
 * @param ctx The helper to use for running async tests on vertx.
 */
@Test
public void testStartUpFailsIfCredentialsAuthProviderIsNotSet(final TestContext ctx) {
    // GIVEN an adapter with a client provided http server
    HttpServer server = getHttpServer(false);
    AbstractVertxBasedHttpProtocolAdapter<HttpProtocolAdapterProperties> adapter = getAdapter(server, s -> ctx.fail("should not have invoked onStartupSuccess"));
    // WHEN starting the adapter
    Async startup = ctx.async();
    Future<Void> startupTracker = Future.future();
    startupTracker.setHandler(ctx.asyncAssertFailure(s -> {
        startup.complete();
    }));
    adapter.start(startupTracker);
    // THEN the onStartupSuccess method has been invoked
    startup.await();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArgumentMatchers(org.mockito.ArgumentMatchers) ProtonDelivery(io.vertx.proton.ProtonDelivery) TenantConstants(org.eclipse.hono.util.TenantConstants) HttpServer(io.vertx.core.http.HttpServer) RunWith(org.junit.runner.RunWith) Router(io.vertx.ext.web.Router) ClientErrorException(org.eclipse.hono.client.ClientErrorException) RoutingContext(io.vertx.ext.web.RoutingContext) TenantClient(org.eclipse.hono.client.TenantClient) MessageSender(org.eclipse.hono.client.MessageSender) Timeout(org.junit.rules.Timeout) Message(org.apache.qpid.proton.message.Message) RegistrationClient(org.eclipse.hono.client.RegistrationClient) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) HonoClient(org.eclipse.hono.client.HonoClient) Before(org.junit.Before) RegistrationConstants(org.eclipse.hono.util.RegistrationConstants) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) Mockito(org.mockito.Mockito) HonoClientBasedAuthProvider(org.eclipse.hono.service.auth.device.HonoClientBasedAuthProvider) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Handler(io.vertx.core.Handler) Async(io.vertx.ext.unit.Async) HttpServer(io.vertx.core.http.HttpServer) Test(org.junit.Test)

Aggregations

HttpServer (io.vertx.core.http.HttpServer)81 Router (io.vertx.ext.web.Router)37 HttpServerOptions (io.vertx.core.http.HttpServerOptions)33 Test (org.junit.Test)22 JsonObject (io.vertx.core.json.JsonObject)17 HttpClient (io.vertx.core.http.HttpClient)13 Future (io.vertx.core.Future)12 Vertx (io.vertx.core.Vertx)12 HttpServerResponse (io.vertx.core.http.HttpServerResponse)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 Buffer (io.vertx.core.buffer.Buffer)11 HttpMethod (io.vertx.core.http.HttpMethod)10 Handler (io.vertx.core.Handler)9 VertxOptions (io.vertx.core.VertxOptions)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 HttpClientOptions (io.vertx.core.http.HttpClientOptions)8 List (java.util.List)8 AbstractVerticle (io.vertx.core.AbstractVerticle)7 File (java.io.File)7 AsyncResult (io.vertx.core.AsyncResult)6