use of javax.validation.ConstraintViolation in project camel by apache.
the class SMSMessageTest method testDynamicFromFieldZeroLength.
@Test
public void testDynamicFromFieldZeroLength() throws Exception {
String zeroLengthDynamicFrom = "";
final SMSMessage m = new SMSMessage("idAsString", "Hello World", validNumber, zeroLengthDynamicFrom);
final Set<ConstraintViolation<SMSMessage>> constraintViolations = validator.validate(m);
Assert.isTrue(1 == constraintViolations.size());
}
use of javax.validation.ConstraintViolation in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOrderedChecksGroup.
@Test
public void validateShouldFailWithOrderedChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OrderedChecks";
final Car car = createCar(null, "D-A");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("manufacturer", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setManufacturer("BMW");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals("D-A", constraintViolation.getInvalidValue());
assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
}
car.setLicensePlate("DD-AB-123");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of javax.validation.ConstraintViolation in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithExpliciteDefaultGroup.
@Test
public void validateShouldFailWithExpliciteDefaultGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=javax.validation.groups.Default";
final Car car = createCar("BMW", null);
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals(null, constraintViolation.getInvalidValue());
assertEquals("may not be null", constraintViolation.getMessage());
}
car.setLicensePlate("D-A");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of javax.validation.ConstraintViolation in project camel by apache.
the class BeanValidatorRouteTest method validateShouldFailWithOptionalChecksGroup.
@Test
public void validateShouldFailWithOptionalChecksGroup() throws Exception {
if (isPlatform("aix")) {
// cannot run on aix
return;
}
final String url = "bean-validator://x?group=org.apache.camel.component.bean.validator.OptionalChecks";
final Car car = createCar("BMW", "D-A");
try {
template.requestBody(url, car);
fail("should throw exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(BeanValidationException.class, e.getCause());
BeanValidationException exception = (BeanValidationException) e.getCause();
Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
assertEquals(1, constraintViolations.size());
ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
assertEquals("D-A", constraintViolation.getInvalidValue());
assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
}
car.setLicensePlate("DD-AB-123");
Exchange exchange = template.request(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(car);
}
});
assertNotNull(exchange);
}
use of javax.validation.ConstraintViolation in project dropwizard by dropwizard.
the class ParamValidatorUnwrapperTest method failsWithInvalidIntParam.
@Test
public void failsWithInvalidIntParam() {
final Example example = new Example();
example.inter = new IntParam("2");
final Set<ConstraintViolation<Example>> validate = validator.validate(example);
assertThat(validate).hasSize(1);
}
Aggregations