Search in sources :

Example 1 with MultipleWarSumConstraint

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();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ResteasyViolationExceptionImpl(org.jboss.resteasy.plugins.validation.ResteasyViolationExceptionImpl) ResteasyViolationException(org.jboss.resteasy.api.validation.ResteasyViolationException) WebTarget(jakarta.ws.rs.client.WebTarget) ResteasyConstraintViolation(org.jboss.resteasy.api.validation.ResteasyConstraintViolation) MultipleWarSumConstraint(org.jboss.resteasy.test.validation.cdi.resource.MultipleWarSumConstraint) Test(org.junit.Test)

Aggregations

WebTarget (jakarta.ws.rs.client.WebTarget)1 Response (jakarta.ws.rs.core.Response)1 ResteasyConstraintViolation (org.jboss.resteasy.api.validation.ResteasyConstraintViolation)1 ResteasyViolationException (org.jboss.resteasy.api.validation.ResteasyViolationException)1 ResteasyViolationExceptionImpl (org.jboss.resteasy.plugins.validation.ResteasyViolationExceptionImpl)1 MultipleWarSumConstraint (org.jboss.resteasy.test.validation.cdi.resource.MultipleWarSumConstraint)1 Test (org.junit.Test)1