use of javax.validation.ConstraintViolationException in project apex-malhar by apache.
the class ParquetFilePOJOReaderTest method testApplication.
@Test
public void testApplication() throws IOException, Exception {
try {
FileContext.getLocalFSFileContext().delete(new Path(new File(testMeta.dir).getAbsolutePath()), true);
List<EventRecord> data = Lists.newArrayList();
data.add(new EventRecord(1, "cust1", 12321L, true, 12.22f, 12.23));
data.add(new EventRecord(2, "cust2", 12322L, true, 22.22f, 22.23));
data.add(new EventRecord(3, "cust3", 12323L, true, 32.22f, 32.23));
writeParquetFile(PARQUET_SCHEMA, new File(testMeta.dir, "data.parquet"), data);
parquetFilePOJOReader.setDirectory(testMeta.dir);
parquetFilePOJOReader.setParquetSchema(PARQUET_SCHEMA);
LocalMode lma = LocalMode.newInstance();
Configuration conf = new Configuration(false);
ParquetReaderApplication parquetReaderApplication = new ParquetReaderApplication();
parquetReaderApplication.setParquetFilePOJOReader(parquetFilePOJOReader);
lma.prepareDAG(parquetReaderApplication, 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 apex-malhar by apache.
the class ApplicationTest method testApplication.
@Test
public void testApplication() throws 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();
lc.runAsync();
// wait for output files to roll
Thread.sleep(5000);
String[] extensions = { "dat.0", "tmp" };
Collection<File> list = FileUtils.listFiles(new File(FILE_NAME), extensions, false);
for (File file : list) {
for (String line : FileUtils.readLines(file)) {
Assert.assertEquals("Delimiter in record", true, (line.equals("1234|0|SimpleCsvFormatterExample|10000.0|||APEX|false|false||")));
}
}
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
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();
lc.runAsync();
Thread.sleep(10 * 1000);
lc.shutdown();
} catch (ConstraintViolationException e) {
Assert.fail("constraint violations: " + e.getConstraintViolations());
}
}
use of javax.validation.ConstraintViolationException in project cxf by apache.
the class BookStore method createBookValidate.
@POST
@Path("/books-validate")
public Response createBookValidate(Book book) {
assertInjections();
BeanValidationProvider prov = new BeanValidationProvider(new ValidationProviderResolver() {
@Override
public List<ValidationProvider<?>> getValidationProviders() {
ValidationProvider<HibernateValidatorConfiguration> prov = new HibernateValidator();
List<ValidationProvider<?>> provs = new ArrayList<>();
provs.add(prov);
return provs;
}
}, HibernateValidator.class);
try {
prov.validateBean(book);
} catch (ConstraintViolationException cve) {
StringBuilder violationMessages = new StringBuilder();
for (ConstraintViolation<?> constraintViolation : cve.getConstraintViolations()) {
violationMessages.append(constraintViolation.getPropertyPath()).append(": ").append(constraintViolation.getMessage()).append("\n");
}
return Response.status(Response.Status.BAD_REQUEST).type("text/plain").entity(violationMessages.toString()).build();
}
return createBook(book);
}
use of javax.validation.ConstraintViolationException in project cxf by apache.
the class JAXRSClientServerValidationSpringTest method testHelloRestValidationFailsIfNameIsNullClient.
@Test
public void testHelloRestValidationFailsIfNameIsNullClient() throws Exception {
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress("http://localhost:" + PORT + "/bwrest");
bean.setServiceClass(BookWorld.class);
bean.setFeatures(Arrays.asList(new JAXRSClientBeanValidationFeature()));
BookWorld service = bean.create(BookWorld.class);
BookWithValidation bw = service.echoBook(new BookWithValidation("RS", "123"));
assertEquals("123", bw.getId());
try {
service.echoBook(new BookWithValidation(null, "123"));
fail("Validation failure expected");
} catch (ConstraintViolationException ex) {
// complete
}
}
Aggregations