Search in sources :

Example 31 with ConstraintViolationException

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());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) File(java.io.File) Test(org.junit.Test)

Example 32 with ConstraintViolationException

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());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) File(java.io.File) Test(org.junit.Test)

Example 33 with ConstraintViolationException

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());
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) LocalMode(com.datatorrent.api.LocalMode) ConstraintViolationException(javax.validation.ConstraintViolationException) Test(org.junit.Test)

Example 34 with ConstraintViolationException

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);
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider) ValidationProvider(javax.validation.spi.ValidationProvider) ConstraintViolation(javax.validation.ConstraintViolation) ValidationProviderResolver(javax.validation.ValidationProviderResolver) ConstraintViolationException(javax.validation.ConstraintViolationException) ArrayList(java.util.ArrayList) List(java.util.List) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 35 with ConstraintViolationException

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
    }
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ConstraintViolationException(javax.validation.ConstraintViolationException) JAXRSClientBeanValidationFeature(org.apache.cxf.jaxrs.client.validation.JAXRSClientBeanValidationFeature) BookWithValidation(org.apache.cxf.systest.jaxrs.validation.BookWithValidation) AbstractJAXRSValidationTest(org.apache.cxf.systest.jaxrs.validation.AbstractJAXRSValidationTest) Test(org.junit.Test)

Aggregations

ConstraintViolationException (javax.validation.ConstraintViolationException)87 Test (org.junit.Test)67 LocalMode (com.datatorrent.api.LocalMode)35 Configuration (org.apache.hadoop.conf.Configuration)34 File (java.io.File)16 ConstraintViolation (javax.validation.ConstraintViolation)15 Session (org.hibernate.Session)11 Transaction (org.hibernate.Transaction)11 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)9 Map (java.util.Map)9 BigDecimal (java.math.BigDecimal)7 HashMap (java.util.HashMap)7 Set (java.util.Set)6 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 HashSet (java.util.HashSet)5 ValidationException (javax.validation.ValidationException)5 Validator (javax.validation.Validator)5 Response (javax.ws.rs.core.Response)5 Path (org.apache.hadoop.fs.Path)5