Search in sources :

Example 81 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();
        // runs for 10 seconds and quits
        lc.run(10000);
    } 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 82 with ConstraintViolationException

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);
}
Also used : Response(javax.ws.rs.core.Response) ResponseConstraintViolationException(org.apache.cxf.validation.ResponseConstraintViolationException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponseConstraintViolationException(org.apache.cxf.validation.ResponseConstraintViolationException)

Example 83 with ConstraintViolationException

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);
    }
}
Also used : ExecutableValidator(javax.validation.executable.ExecutableValidator) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException)

Example 84 with ConstraintViolationException

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

Example 85 with ConstraintViolationException

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