use of javax.validation.ConstraintViolation in project wildfly by wildfly.
the class BeanValidationIntegrationTestCase method testJndiBoundValidatorFactoryIsCdiEnabled.
@Test
public void testJndiBoundValidatorFactoryIsCdiEnabled() throws NamingException {
ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory");
assertNotNull(validatorFactory);
Set<ConstraintViolation<Reservation>> violations = validatorFactory.getValidator().validate(new Reservation(4, null));
List<String> actualViolations = new ArrayList<String>();
for (ConstraintViolation<?> violation : violations) {
actualViolations.add(violation.getMessage());
}
List<String> expectedViolations = new ArrayList<String>();
expectedViolations.add("may not be null");
expectedViolations.add("Not enough people for a reservation");
Collections.sort(actualViolations);
Collections.sort(expectedViolations);
assertEquals(expectedViolations, actualViolations);
}
use of javax.validation.ConstraintViolation in project tomee by apache.
the class ConstraintViolationExceptionMapper method getConstraintViolationErrors.
private static Object getConstraintViolationErrors(final ConstraintViolationException ex) {
final List<ErrorResponse> errors = new ArrayList<ErrorResponse>();
for (final ConstraintViolation violation : ex.getConstraintViolations()) {
final ErrorResponse error = new ErrorResponse();
error.setMessage(violation.getMessage());
errors.add(error);
}
return new ErrorList<ErrorResponse>(errors);
}
use of javax.validation.ConstraintViolation in project AngularBeans by bessemHmidi.
the class BeanValidator method validate.
public Set validate(Object bean) {
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Validator validator = vf.getValidator();
Set<ConstraintViolation<Object>> errors = validator.validate(bean);
for (ConstraintViolation<Object> violation : errors) {
System.out.println((violation.getInvalidValue()) + ":" + violation.getMessage());
// System.out.println(violation.getClass());
}
return errors;
}
use of javax.validation.ConstraintViolation in project API by ca-cwds.
the class CmsDocumentBlobSegmentTest method testColumnConstraintsGood.
@Test
public void testColumnConstraintsGood() throws Exception {
CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, segmentSequence, docBlob);
Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
assertEquals(0, violations.size());
}
use of javax.validation.ConstraintViolation in project API by ca-cwds.
the class CmsDocumentBlobSegmentTest method testConstraintBlobNull.
// ====================
// BLOB
// ====================
@Test
public void testConstraintBlobNull() throws Exception {
CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, segmentSequence, null);
Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
assertEquals(1, violations.size());
assertEquals("may not be null", violations.iterator().next().getMessage());
}
Aggregations