Search in sources :

Example 46 with ConstraintViolation

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);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 47 with ConstraintViolation

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);
}
Also used : ErrorList(org.superbiz.webapp1.messages.ErrorList) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) ErrorResponse(org.superbiz.webapp1.messages.ErrorResponse)

Example 48 with ConstraintViolation

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;
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator)

Example 49 with ConstraintViolation

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());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 50 with ConstraintViolation

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());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Aggregations

ConstraintViolation (javax.validation.ConstraintViolation)95 Test (org.junit.Test)78 Validator (javax.validation.Validator)19 ConstraintViolationException (javax.validation.ConstraintViolationException)12 SMSMessage (org.apache.camel.component.cm.client.SMSMessage)12 ChangePasswordForm (org.orcid.frontend.web.forms.ChangePasswordForm)11 CmsDocumentBlobSegment (gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment)10 ValidatorFactory (javax.validation.ValidatorFactory)9 ManagePasswordOptionsForm (org.orcid.frontend.web.forms.ManagePasswordOptionsForm)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 CMConfiguration (org.apache.camel.component.cm.CMConfiguration)6 Set (java.util.Set)5 InitialContext (javax.naming.InitialContext)5 Session (org.hibernate.Session)5 Transaction (org.hibernate.Transaction)5 Method (java.lang.reflect.Method)4 ExecutableValidator (javax.validation.executable.ExecutableValidator)4 CamelExecutionException (org.apache.camel.CamelExecutionException)4 Exchange (org.apache.camel.Exchange)4