Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(itest): Send status code during exceptional future completion #585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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