Skip to content

Commit

Permalink
Send status code with exceptional completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Janelle Law committed Jul 19, 2021
1 parent 8671760 commit 2a8367c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/test/java/itest/RulesPostFormIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
}
}
11 changes: 11 additions & 0 deletions src/test/java/itest/RulesPostJsonIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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"));
}
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
}
}
5 changes: 4 additions & 1 deletion src/test/java/itest/bases/StandardSelfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,12 +131,14 @@ public static boolean assertRequestStatus(
if (result.failed()) {
result.cause().printStackTrace();
future.completeExceptionally(result.cause());

return false;
}
HttpResponse<Buffer> 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;
Expand Down

0 comments on commit 2a8367c

Please sign in to comment.