diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java index e2f5cfa7c0..b29d036532 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java @@ -54,7 +54,6 @@ import java.util.stream.Collectors; import static io.vertx.core.Future.succeededFuture; -import static org.junit.Assert.assertNotEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -1044,8 +1043,8 @@ public void testRegexWithNamedParamsKeepsIndexedParams() throws Exception { public void testConsumes() throws Exception { router.route().consumes("text/html").handler(rc -> rc.response().end()); testRequestWithContentType(HttpMethod.GET, "/foo", "text/html", 200, "OK"); - testRequestWithContentType(HttpMethod.GET, "/foo", "text/json", 415, "Unsupported Media Type"); - testRequestWithContentType(HttpMethod.GET, "/foo", "something/html", 415, "Unsupported Media Type"); + testRequestWithContentTypeAndResponseHeader(HttpMethod.GET, "/foo", "text/json", 415, "Unsupported Media Type", Map.of("Accept", "text/html")); + testRequestWithContentTypeAndResponseHeader(HttpMethod.GET, "/foo", "something/html", 415, "Unsupported Media Type", Map.of("Accept", "text/html")); } @Test @@ -1469,7 +1468,7 @@ public void testGetRoutesRecursive() throws Exception { router.route("/sub/*").subRouter(subRouter); List routes = router.getRoutes(); assertEquals(2, routes.size()); - for(Route route: routes) { + for (Route route : routes) { Router theSubRouter = route.getSubRouter(); if (route.getPath().equals("/sub/")) { assertNotNull(theSubRouter); @@ -2446,8 +2445,8 @@ public void testMultipleHandlersMultipleConnectionsDelayedMixed() throws Excepti // using executeBlocking should create multiple connections vertx.executeBlocking((new Random().nextBoolean() ? execute200Request : execute400Request), false) .onComplete(onSuccess(v -> { - latch.countDown(); - })); + latch.countDown(); + })); } awaitLatch(latch); } @@ -3538,12 +3537,12 @@ public void testPausedConnection() { ctx.response().end(ctx.normalizedPath() + "\n"); }); - int numRequests= 20; + int numRequests = 20; waitFor(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); - for (int i = 0;i < numRequests;i++) { + for (int i = 0; i < numRequests; i++) { client.request(new RequestOptions().setMethod(HttpMethod.PUT).setPort(8080)).onComplete(onSuccess(req -> { // 8192 * 8 fills the HTTP server request pending queue // => pauses the HttpConnection (see Http1xServerRequest#handleContent(Buffer) that calls Http1xServerConnection#doPause()) @@ -3573,12 +3572,12 @@ public void testPausedConnection2() { router.route("/") .handler(BodyHandler.create()); - int numRequests= 20; + int numRequests = 20; waitFor(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); - for (int i = 0;i < numRequests;i++) { + for (int i = 0; i < numRequests; i++) { client.request(new RequestOptions().setMethod(HttpMethod.PUT).setPort(8080)).onComplete(onSuccess(req -> { // 8192 * 8 fills the HTTP server request pending queue // => pauses the HttpConnection (see Http1xServerRequest#handleContent(Buffer) that calls Http1xServerConnection#doPause()) @@ -3611,12 +3610,12 @@ public void testPausedConnection3() { ctx.request().endHandler(done -> ctx.response().end(ctx.normalizedPath() + "\n")); }); - int numRequests= 20; + int numRequests = 20; waitFor(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); - for (int i = 0;i < numRequests;i++) { + for (int i = 0; i < numRequests; i++) { client.request(new RequestOptions().setMethod(HttpMethod.PUT).setPort(8080)).onComplete(onSuccess(req -> { // 8192 * 8 fills the HTTP server request pending queue // => pauses the HttpConnection (see Http1xServerRequest#handleContent(Buffer) that calls Http1xServerConnection#doPause()) @@ -3639,12 +3638,12 @@ public void testPausedConnection4() { .setTimer(1L, t -> ctx.next()); }); - int numRequests= 20; + int numRequests = 20; waitFor(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); - for (int i = 0;i < numRequests;i++) { + for (int i = 0; i < numRequests; i++) { client.request(new RequestOptions().setMethod(HttpMethod.PUT).setPort(8080)).onComplete(onSuccess(req -> { // 8192 * 8 fills the HTTP server request pending queue // => pauses the HttpConnection (see Http1xServerRequest#handleContent(Buffer) that calls Http1xServerConnection#doPause()) diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java index 817e422d7f..a6aaa30a78 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java @@ -31,10 +31,7 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; @@ -140,6 +137,10 @@ protected void testRequestWithContentType(HttpMethod method, String path, String testRequest(method, path, req -> req.putHeader("content-type", contentType), statusCode, statusMessage, null); } + protected void testRequestWithContentTypeAndResponseHeader(HttpMethod method, String path, String contentType, int statusCode, String statusMessage, Map headers) throws Exception { + testRequest(method, path, req -> req.putHeader("content-type", contentType), res -> headers.forEach((key, val) -> assertEquals(val, res.getHeader(key))), statusCode, statusMessage, null); + } + protected void testRequestWithAccepts(RequestOptions requestOptions, String accepts, int statusCode, String statusMessage) throws Exception { testRequest(requestOptions, req -> req.putHeader("accept", accepts), statusCode, statusMessage, null); } @@ -161,6 +162,7 @@ protected void testRequest(RequestOptions requestOptions, Consumer requestAction, int statusCode, String statusMessage, String responseBody) throws Exception { @@ -172,6 +174,7 @@ protected void testRequest(RequestOptions requestOptions, Consumer requestAction, Consumer responseAction, int statusCode, String statusMessage, String responseBody) throws Exception { @@ -183,6 +186,7 @@ protected void testRequestBuffer(RequestOptions requestOptions, Consumer requestAction, Consumer responseAction, int statusCode, String statusMessage, Buffer responseBodyBuffer) throws Exception {