use of org.jboss.resteasy.api.validation.ResteasyViolationException in project resteasy by resteasy.
the class MultipleWarTest method testInputsInvalid.
/**
* @tpTestDetails Check validation of invalid inputs
* @tpSince RESTEasy 3.0.16
*/
@Test
public void testInputsInvalid() throws Exception {
WebTarget request1 = client.target(generateURL("1/test/0/0/0"));
WebTarget request2 = client.target(generateURL("2/test/0/0/0"));
Response response;
for (int i = 1; i < 2; i++) {
response = request1.request().get();
String answer = response.readEntity(String.class);
assertEquals(HttpResponseCodes.SC_BAD_REQUEST, response.getStatus());
ResteasyViolationException e = new ResteasyViolationExceptionImpl(String.class.cast(answer));
TestUtil.countViolations(e, 4, 2, 1, 1, 0);
ResteasyConstraintViolation cv = TestUtil.getViolationByMessage(e.getPropertyViolations(), "must be greater than or equal to 3");
Assert.assertNotNull(WRONG_ERROR_MSG, cv);
cv = TestUtil.getViolationByMessage(e.getPropertyViolations(), "must be greater than or equal to 5");
Assert.assertNotNull(WRONG_ERROR_MSG, cv);
cv = e.getClassViolations().iterator().next();
Assert.assertTrue(WRONG_ERROR_MSG, cv.getMessage().indexOf("org.jboss.resteasy.resteasy1058.MultipleWarSumConstraint") > 0);
cv = e.getParameterViolations().iterator().next();
Assert.assertTrue(WRONG_ERROR_MSG, cv.getMessage().equals("must be greater than or equal to 7"));
response.close();
response = request2.request().get();
answer = response.readEntity(String.class);
assertEquals(HttpResponseCodes.SC_BAD_REQUEST, response.getStatus());
e = new ResteasyViolationExceptionImpl(String.class.cast(answer));
TestUtil.countViolations(e, 4, 2, 1, 1, 0);
cv = TestUtil.getViolationByMessage(e.getPropertyViolations(), "must be greater than or equal to 3");
Assert.assertNotNull(WRONG_ERROR_MSG, cv);
cv = TestUtil.getViolationByMessage(e.getPropertyViolations(), "must be greater than or equal to 5");
Assert.assertNotNull(WRONG_ERROR_MSG, cv);
cv = e.getClassViolations().iterator().next();
Assert.assertTrue(WRONG_ERROR_MSG, cv.getMessage().indexOf("org.jboss.resteasy.resteasy1058.MultipleWarSumConstraint") > 0);
cv = e.getParameterViolations().iterator().next();
Assert.assertTrue(WRONG_ERROR_MSG, cv.getMessage().equals("must be greater than or equal to 7"));
response.close();
}
}
use of org.jboss.resteasy.api.validation.ResteasyViolationException in project resteasy by resteasy.
the class MissingCDITest method testMissingCDIInvalid.
@Test
public void testMissingCDIInvalid() throws Exception {
Response response = ResteasyClientBuilder.newClient().target(baseUri.toString() + "test/0").request().get();
String entity = response.readEntity(String.class);
assertEquals(400, response.getStatus());
ResteasyViolationException e = new ResteasyViolationExceptionImpl(entity);
countViolations(e, 1, 0, 0, 1, 0);
ResteasyConstraintViolation cv = e.getParameterViolations().iterator().next();
Assert.assertTrue(cv.getMessage().equals("must be greater than or equal to 7"));
}
use of org.jboss.resteasy.api.validation.ResteasyViolationException in project nessie by projectnessie.
the class ResteasyExceptionMapper method toResponse.
@Override
public Response toResponse(ResteasyViolationException exception) {
Exception e = exception.getException();
if (e == null) {
boolean returnValueViolation = !exception.getReturnValueViolations().isEmpty();
ErrorCode errorCode = returnValueViolation ? ErrorCode.UNKNOWN : ErrorCode.BAD_REQUEST;
return buildExceptionResponse(errorCode, exception.getMessage(), exception, // no need to send the stack trace for a validation-error
false, b -> b.header(Validation.VALIDATION_HEADER, "true"));
}
return buildExceptionResponse(ErrorCode.UNKNOWN, unwrapException(exception), exception);
}
Aggregations