use of org.jboss.resteasy.test.validation.cdi.resource.MultipleWarSumConstraint 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();
}
}
Aggregations