From 2a8367cc8f5327ba1c29fc7bd802eef775e947ba Mon Sep 17 00:00:00 2001 From: Janelle Law Date: Mon, 19 Jul 2021 16:23:58 -0400 Subject: [PATCH] Send status code with exceptional completion --- src/test/java/itest/RulesPostFormIT.java | 7 +++++++ src/test/java/itest/RulesPostJsonIT.java | 11 +++++++++++ src/test/java/itest/bases/StandardSelfTest.java | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/java/itest/RulesPostFormIT.java b/src/test/java/itest/RulesPostFormIT.java index 70c663834e..673a115c5a 100644 --- a/src/test/java/itest/RulesPostFormIT.java +++ b/src/test/java/itest/RulesPostFormIT.java @@ -47,6 +47,7 @@ import io.vertx.core.MultiMap; import io.vertx.core.http.HttpHeaders; import io.vertx.core.json.JsonObject; +import io.vertx.ext.web.handler.impl.HttpStatusException; import itest.bases.StandardSelfTest; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -87,6 +88,8 @@ void testAddRuleThrowsWhenFormAttributesNull() throws Exception { }); ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); } @@ -129,6 +132,8 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { ExecutionException ex = Assertions.assertThrows( ExecutionException.class, () -> duplicatePostResponse.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(409)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Conflict")); } finally { @@ -172,6 +177,8 @@ void testAddRuleThrowsWhenIntegerAttributesNegative() throws Exception { ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); } } diff --git a/src/test/java/itest/RulesPostJsonIT.java b/src/test/java/itest/RulesPostJsonIT.java index 24a3d1f787..f55caa04d7 100644 --- a/src/test/java/itest/RulesPostJsonIT.java +++ b/src/test/java/itest/RulesPostJsonIT.java @@ -46,6 +46,7 @@ import io.vertx.core.http.HttpHeaders; import io.vertx.core.json.JsonObject; +import io.vertx.ext.web.handler.impl.HttpStatusException; import itest.bases.StandardSelfTest; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -86,6 +87,8 @@ void testAddRuleThrowsWhenJsonAttributesNull() throws Exception { }); ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); } @@ -103,6 +106,8 @@ void testAddRuleThrowsWhenMimeUnsupported() throws Exception { }); ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(415)); MatcherAssert.assertThat( ex.getCause().getMessage(), Matchers.equalTo("Unsupported Media Type")); } @@ -121,6 +126,8 @@ void testAddRuleThrowsWhenMimeInvalid() throws Exception { }); ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(415)); MatcherAssert.assertThat( ex.getCause().getMessage(), Matchers.equalTo("Unsupported Media Type")); } @@ -164,6 +171,8 @@ void testAddRuleThrowsWhenRuleNameAlreadyExists() throws Exception { ExecutionException ex = Assertions.assertThrows( ExecutionException.class, () -> duplicatePostResponse.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(409)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Conflict")); } finally { @@ -207,6 +216,8 @@ void testAddRuleThrowsWhenIntegerAttributesNegative() throws Exception { ExecutionException ex = Assertions.assertThrows(ExecutionException.class, () -> response.get()); + MatcherAssert.assertThat( + ((HttpStatusException) ex.getCause()).getStatusCode(), Matchers.equalTo(400)); MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request")); } } diff --git a/src/test/java/itest/bases/StandardSelfTest.java b/src/test/java/itest/bases/StandardSelfTest.java index 5671c3ff88..7f6cf3df66 100644 --- a/src/test/java/itest/bases/StandardSelfTest.java +++ b/src/test/java/itest/bases/StandardSelfTest.java @@ -58,6 +58,7 @@ import io.vertx.ext.web.client.HttpRequest; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.WebClient; +import io.vertx.ext.web.handler.impl.HttpStatusException; import itest.util.Podman; import itest.util.Utils; import org.apache.http.client.utils.URLEncodedUtils; @@ -130,12 +131,14 @@ public static boolean assertRequestStatus( if (result.failed()) { result.cause().printStackTrace(); future.completeExceptionally(result.cause()); + return false; } HttpResponse response = result.result(); if (!HttpStatusCodeIdentifier.isSuccessCode(response.statusCode())) { System.err.println("HTTP " + response.statusCode() + ": " + response.statusMessage()); - future.completeExceptionally(new Exception(response.statusMessage())); + future.completeExceptionally( + new HttpStatusException(response.statusCode(), response.statusMessage())); return false; } return true;