diff --git a/src/main/java/io/cryostat/util/IllegalArgumentExceptionMapper.java b/src/main/java/io/cryostat/util/IllegalArgumentExceptionMapper.java new file mode 100644 index 000000000..6d5a619e9 --- /dev/null +++ b/src/main/java/io/cryostat/util/IllegalArgumentExceptionMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright The Cryostat Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.cryostat.util; + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.ExceptionMapper; +import jakarta.ws.rs.ext.Provider; + +@Provider +public class IllegalArgumentExceptionMapper implements ExceptionMapper { + @Override + public Response toResponse(IllegalArgumentException exception) { + return Response.status(400).build(); + } +} diff --git a/src/test/java/itest/RulesPostJsonIT.java b/src/test/java/itest/RulesPostJsonIT.java index 003777bda..838ff1f6b 100644 --- a/src/test/java/itest/RulesPostJsonIT.java +++ b/src/test/java/itest/RulesPostJsonIT.java @@ -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) @@ -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 { @@ -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