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;
}
};
}
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));
}
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
}
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();
}
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();
}
Aggregations