use of javax.validation.Validator in project javaee7-firstcup by ecabrerar.
the class BooksCollectionTest method shouldReturnAValidationError.
@Test
public void shouldReturnAValidationError() {
Book book = new Book("Effective Java", "2234555568", "");
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Book>> violations = validator.validate(book);
Assert.assertEquals(2, violations.size());
System.out.println(violations.stream().map(error -> error.getMessage()).collect(Collectors.joining(", ")));
}
use of javax.validation.Validator in project opennms by OpenNMS.
the class EventValidationTest method testBadState.
@Test
public void testBadState() throws Exception {
final Validator validator = factory.getValidator();
final Event event = new Event();
event.setSource("tests");
event.setTime(new Date());
final Operaction action = new Operaction();
action.setState("monkey");
event.addOperaction(action);
final Set<ConstraintViolation<Event>> errors = validator.validate(event);
LOG.debug("errors: {}", errors);
assertEquals(2, errors.size());
}
use of javax.validation.Validator in project opennms by OpenNMS.
the class EventValidationTest method testBadDbid.
@Test
public void testBadDbid() throws Exception {
final Validator validator = factory.getValidator();
final Event event = new Event();
event.setSource("tests");
event.setTime(new Date());
event.setDbid(-1);
final Set<ConstraintViolation<Event>> errors = validator.validate(event);
assertEquals(1, errors.size());
}
use of javax.validation.Validator in project opennms by OpenNMS.
the class EventValidationTest method testEmptySource.
@Test
public void testEmptySource() throws Exception {
final Validator validator = factory.getValidator();
final Event event = new Event();
event.setTime(new Date());
final Set<ConstraintViolation<Event>> errors = validator.validate(event);
assertNull(event.getSource());
assertEquals(1, errors.size());
}
use of javax.validation.Validator in project tomee by apache.
the class LazyValidatorTest method serialize.
@Test
public void serialize() {
final Serializable obj = Serializable.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ValidatorFactory.class }, new LazyValidator(Validation.buildDefaultValidatorFactory())));
final LazyValidator deserialized = LazyValidator.class.cast(Proxy.getInvocationHandler(SerializationUtils.deserialize(SerializationUtils.serialize(obj))));
final Validator validator = deserialized.getValidator();
assertNotNull(validator);
}
Aggregations