use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class ApplicationTest method testApplication.
@Test
public void testApplication() throws IOException, Exception {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
lma.prepareDAG(new Application(), conf);
LocalMode.Controller lc = lma.getController();
// runs for 10 seconds and quits
lc.run(10000);
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
use of javax.validation.ConstraintViolationException in project cxf by apache.
the class ValidationExceptionMapper method toResponse.
@Override
public Response toResponse(ValidationException exception) {
Response.Status errorStatus = Response.Status.INTERNAL_SERVER_ERROR;
if (exception instanceof ConstraintViolationException) {
StringBuilder responseBody = addMessageToResponse ? new StringBuilder() : null;
final ConstraintViolationException constraint = (ConstraintViolationException) exception;
for (final ConstraintViolation<?> violation : constraint.getConstraintViolations()) {
String message = buildErrorMessage(violation);
if (responseBody != null) {
responseBody.append(message).append("\n");
}
LOG.log(Level.WARNING, message);
}
if (!(constraint instanceof ResponseConstraintViolationException)) {
errorStatus = Response.Status.BAD_REQUEST;
}
return buildResponse(errorStatus, responseBody != null ? responseBody.toString() : null);
}
return buildResponse(errorStatus, addMessageToResponse ? exception.getMessage() : null);
}
use of javax.validation.ConstraintViolationException in project cxf by apache.
the class BeanValidationProvider method validateParameters.
public <T> void validateParameters(final T instance, final Method method, final Object[] arguments) {
final ExecutableValidator methodValidator = getExecutableValidator();
final Set<ConstraintViolation<T>> violations = methodValidator.validateParameters(instance, method, arguments);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class FileEndpointTest method testApplication.
@Test
public void testApplication() throws Exception {
File modelFile = new File("src/test/resources/model/model_file_csv.json");
String model = FileUtils.readFileToString(modelFile);
PrintStream originalSysout = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
lma.prepareDAG(new Application(model), conf);
LocalMode.Controller lc = lma.getController();
lc.runAsync();
waitTillStdoutIsPopulated(baos, 30000);
lc.shutdown();
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
} catch (Exception e) {
Assert.fail("Exception: " + e);
}
System.setOut(originalSysout);
String[] sout = baos.toString().split(System.lineSeparator());
Collection<String> filter = Collections2.filter(Arrays.asList(sout), Predicates.containsPattern("Delta Record:"));
String[] actualLines = filter.toArray(new String[filter.size()]);
Assert.assertEquals(6, actualLines.length);
Assert.assertTrue(actualLines[0].contains("RowTime=Mon Feb 15 10:15:00 GMT 2016, Product=paint1"));
Assert.assertTrue(actualLines[1].contains("RowTime=Mon Feb 15 10:16:00 GMT 2016, Product=paint2"));
Assert.assertTrue(actualLines[2].contains("RowTime=Mon Feb 15 10:17:00 GMT 2016, Product=paint3"));
Assert.assertTrue(actualLines[3].contains("RowTime=Mon Feb 15 10:18:00 GMT 2016, Product=paint4"));
Assert.assertTrue(actualLines[4].contains("RowTime=Mon Feb 15 10:19:00 GMT 2016, Product=paint5"));
Assert.assertTrue(actualLines[5].contains("RowTime=Mon Feb 15 10:10:00 GMT 2016, Product=abcde6"));
}
use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class TransformOperatorAppTest method testExpressionApplication.
@Test
public void testExpressionApplication() throws Exception {
try {
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
lma.prepareDAG(new Application(), conf);
LocalMode.Controller lc = lma.getController();
// runs for 10 seconds and quits
lc.run(10000);
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
Aggregations