Search in sources :

Example 1 with FailureHandler

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);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) FailureHandler(com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor.FailureHandler) Request(com.predic8.membrane.core.http.Request) ResolverMap(com.predic8.membrane.core.resolver.ResolverMap)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)1 Request (com.predic8.membrane.core.http.Request)1 FailureHandler (com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor.FailureHandler)1 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)1