Search in sources :

Example 91 with ValidatorFactory

use of javax.validation.ValidatorFactory in project motech by motech.

the class MdsConfig method addBeanValidationFactoryProperty.

private void addBeanValidationFactoryProperty(Properties properties) {
    // Datanucleus expects the validator factory as the actual object, not just a string property
    ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
    properties.put(PropertyNames.PROPERTY_VALIDATION_FACTORY, validatorFactory);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory)

Example 92 with ValidatorFactory

use of javax.validation.ValidatorFactory in project wicket by apache.

the class DefaultValidatorProvider method get.

@Override
public Validator get() {
    if (validator == null) {
        Configuration<?> config = Validation.byDefaultProvider().configure();
        MessageInterpolator interpolator = config.getDefaultMessageInterpolator();
        interpolator = new SessionLocaleInterpolator(interpolator);
        ValidatorFactory factory = config.messageInterpolator(interpolator).buildValidatorFactory();
        validator = factory.getValidator();
    }
    return validator;
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) MessageInterpolator(javax.validation.MessageInterpolator)

Example 93 with ValidatorFactory

use of javax.validation.ValidatorFactory in project ART-TIME by Artezio.

the class HoursTest method testValidateNegativeQuantity.

@Test
public void testValidateNegativeQuantity() {
    ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
    Validator validator = vf.getValidator();
    Hours h = new Hours(new Project(), new Date(), new Employee("user"), new HourType("type1"));
    h.setQuantity(BigDecimal.valueOf(-1.0));
    Set<ConstraintViolation<Hours>> violations = validator.validate(h);
    vf.close();
    assertFalse(violations.isEmpty());
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) Date(java.util.Date) Test(org.junit.Test)

Example 94 with ValidatorFactory

use of javax.validation.ValidatorFactory in project Payara by payara.

the class CompositeUtil method initBeanValidator.

private static synchronized void initBeanValidator() {
    if (beanValidator != null) {
        return;
    }
    ClassLoader cl = System.getSecurityManager() == null ? Thread.currentThread().getContextClassLoader() : AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

        @Override
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }
    });
    try {
        Thread.currentThread().setContextClassLoader(Validation.class.getClassLoader());
        ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        ValidatorContext validatorContext = validatorFactory.usingContext();
        validatorContext.messageInterpolator(new MessageInterpolatorImpl());
        beanValidator = validatorContext.getValidator();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : Validation(javax.validation.Validation) ValidatorFactory(javax.validation.ValidatorFactory) PrivilegedAction(java.security.PrivilegedAction) ValidatorContext(javax.validation.ValidatorContext) MessageInterpolatorImpl(org.jvnet.hk2.config.MessageInterpolatorImpl)

Example 95 with ValidatorFactory

use of javax.validation.ValidatorFactory in project keywhiz by square.

the class ValidX500NameValidatorTest method setUp.

@BeforeClass
public static void setUp() {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

ValidatorFactory (javax.validation.ValidatorFactory)106 Validator (javax.validation.Validator)31 Before (org.junit.Before)28 ConstraintViolation (javax.validation.ConstraintViolation)25 Test (org.junit.Test)17 BeforeClass (org.junit.BeforeClass)13 ConstraintViolationException (javax.validation.ConstraintViolationException)7 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)6 ResourceBundleMessageInterpolator (org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator)6 PlatformResourceBundleLocator (org.hibernate.validator.resourceloading.PlatformResourceBundleLocator)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 BeanManager (javax.enterprise.inject.spi.BeanManager)5 InitialContext (javax.naming.InitialContext)5 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)5 HashSet (java.util.HashSet)4 NamingException (javax.naming.NamingException)4 ConstraintValidatorFactory (javax.validation.ConstraintValidatorFactory)4 ValidatorContext (javax.validation.ValidatorContext)4 HibernateValidator (org.hibernate.validator.HibernateValidator)4