use of com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor.FailureHandler in project service-proxy by membrane.
the class JSONSchemaValidationTest method validate.
private void validate(String schema, String json, boolean success) throws IOException, Exception {
final StringBuffer sb = new StringBuffer();
FailureHandler fh = new FailureHandler() {
@Override
public void handleFailure(String message, Exchange exc) {
sb.append(message);
sb.append("\n");
}
};
JSONValidator jsonValidator = new JSONValidator(new ResolverMap(), schema, fh);
Request request = new Request.Builder().body(IOUtils.toByteArray(getClass().getResourceAsStream(json))).build();
Exchange exchange = new Exchange(null);
jsonValidator.validateMessage(exchange, request, "request");
if (success)
Assert.assertTrue(sb.toString(), sb.length() == 0);
else
Assert.assertTrue("No error occurred, but expected one.", sb.length() != 0);
}
Aggregations