Skip to content

Commit

Permalink
test(itest): overwrite the IllegalArgumentException http code (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkonno authored Nov 21, 2023
1 parent 829584d commit 20e0304
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/main/java/io/cryostat/ExceptionMappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public RestResponse<Void> mapScriptException(ScriptException ex) {
public RestResponse<Void> mapNoSuchKeyException(NoSuchKeyException ex) {
return RestResponse.status(HttpResponseStatus.NOT_FOUND.code());
}

@ServerExceptionMapper
public RestResponse<Void> mapIllegalArgumentException(IllegalArgumentException exception) {
return RestResponse.status(HttpResponseStatus.BAD_REQUEST.code());
}
}
12 changes: 2 additions & 10 deletions src/test/java/itest/RulesPostJsonIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;

@QuarkusIntegrationTest
@TestMethodOrder(OrderAnnotation.class)
Expand Down Expand Up @@ -107,12 +106,6 @@ void testAddRuleThrowsWhenMimeUnsupported() throws Exception {
ex.getCause().getMessage(), Matchers.equalTo("Unsupported Media Type"));
}

@DisabledIfEnvironmentVariable(
named = "CI",
matches = "true",
disabledReason =
"The server 500 seems to cause issues for the next test in the suite, ex. HTTP"
+ " connection closed when attempting to POST the next rule definition")
@Test
@Order(3)
void testAddRuleThrowsWhenMimeInvalid() throws Exception {
Expand All @@ -131,9 +124,8 @@ void testAddRuleThrowsWhenMimeInvalid() throws Exception {
Assertions.assertThrows(
ExecutionException.class, () -> response.get(10, TimeUnit.SECONDS));
MatcherAssert.assertThat(
((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(500));
MatcherAssert.assertThat(
ex.getCause().getMessage(), Matchers.equalTo("Internal Server Error"));
((HttpException) ex.getCause()).getStatusCode(), Matchers.equalTo(400));
MatcherAssert.assertThat(ex.getCause().getMessage(), Matchers.equalTo("Bad Request"));
}

@Test
Expand Down

0 comments on commit 20e0304

Please sign in to comment.