// Sub-resource locator returns resource with invalid field.
request = new ClientRequest(generateURL("/invalidField"));
response = request.post(String.class);
Assert.assertEquals(400, response.getStatus());
Object entity = response.getEntity();
ViolationReport r = new ViolationReport(String.class.cast(entity));
countViolations(r, 1, 0, 0, 0, 0);
ResteasyConstraintViolation cv = r.getFieldViolations().iterator().next();
Assert.assertEquals("size must be between 2 and 4", cv.getMessage());
Assert.assertEquals("abcde", cv.getValue());
// Sub-resource locator returns resource with valid property.
// Note: The resource TestResourceWithProperty has a @PathParam annotation used by a setter,
// but it is not used when TestResourceWithProperty is used a sub-resource. Hence "unused".
request = new ClientRequest(generateURL("/property/abc/unused"));
response = request.post();
Assert.assertEquals(204, response.getStatus());
response.releaseConnection();
// Sub-resource locator returns resource with invalid property.
request = new ClientRequest(generateURL("/property/abcdef/unused"));
response = request.post(String.class);
Assert.assertEquals(400, response.getStatus());
entity = response.getEntity();
r = new ViolationReport(String.class.cast(entity));
countViolations(r, 0, 1, 0, 0, 0);
cv = r.getPropertyViolations().iterator().next();
Assert.assertEquals("size must be between 2 and 4", cv.getMessage());
Assert.assertEquals("abcdef", cv.getValue());
// Valid
request = new ClientRequest(generateURL("/everything/abc/wxyz/unused/unused"));
Foo foo = new Foo("pqrs");
request.body("application/foo", foo);
response = request.post(Foo.class);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(foo, response.getEntity());
// Invalid: Should have 1 each of field, property, class, and parameter violations,and no return value violations.
// Note: expect warning because TestResourceWithAllFivePotentialViolations is being used a sub-resource and it has an injectible field:
// WARN org.jboss.resteasy.core.ResourceLocator - Field s of subresource org.jboss.resteasy.test.validation.TestValidation$TestResourceWithAllFivePotentialViolations will not be injected according to spec
request = new ClientRequest(generateURL("/everything/a/z/unused/unused"));
foo = new Foo("p");
request.body("application/foo", foo);
response = request.post(Foo.class);
Assert.assertEquals(400, response.getStatus());
entity = response.getEntity(String.class);
r = new ViolationReport(String.class.cast(entity));
countViolations(r, 1, 1, 1, 1, 0);
cv = r.getFieldViolations().iterator().next();
Assert.assertEquals("size must be between 2 and 4", cv.getMessage());
Assert.assertEquals("a", cv.getValue());
cv = r.getPropertyViolations().iterator().next();
Assert.assertEquals("size must be between 3 and 5", cv.getMessage());
cv = r.getClassViolations().iterator().next();
Assert.assertEquals("Concatenation of s and t must have length > 5", cv.getMessage());
Assert.assertTrue(cv.getValue().startsWith("org.jboss.resteasy.test.validation.TestValidation$TestResourceWithAllFivePotentialViolations@"));
// Sub-sub-resource locator returns resource with valid property.
request = new ClientRequest(generateURL("/locator/sublocator/abc"));
response = request.post();
Assert.assertEquals(204, response.getStatus());
response.releaseConnection();
// Sub-resource locator returns resource with invalid property.
request = new ClientRequest(generateURL("/locator/sublocator/abcdef"));
response = request.post(String.class);
Assert.assertEquals(400, response.getStatus());
entity = response.getEntity(String.class);
r = new ViolationReport(String.class.cast(entity));
countViolations(r, 1, 0, 0, 0, 0);
cv = r.getFieldViolations().iterator().next();
Assert.assertEquals("size must be between 2 and 3", cv.getMessage());
Assert.assertEquals("abcdef", cv.getValue());
after();
}