Search in sources :

Example 76 with ValidatorFactory

use of javax.validation.ValidatorFactory in project kie-wb-common by kiegroup.

the class SequenceFlowPriorityTest method init.

@Before
public void init() {
    ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
    this.validator = vf.getValidator();
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) Before(org.junit.Before)

Example 77 with ValidatorFactory

use of javax.validation.ValidatorFactory in project kie-wb-common by kiegroup.

the class StartNoneEventTest method init.

@Before
public void init() {
    ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
    this.validator = vf.getValidator();
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) Before(org.junit.Before)

Example 78 with ValidatorFactory

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

the class BVIntegrationTestServlet method configureValidation.

private Validator configureValidation(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    PrintWriter out = resp.getWriter();
    GenericBootstrap bootstrap = Validation.byDefaultProvider();
    Configuration config = bootstrap.configure();
    InputStream mappingsXml = new ByteArrayInputStream(validationXml.getBytes());
    config.addMapping(mappingsXml);
    ValidatorFactory factory = config.buildValidatorFactory();
    ValidatorContext validatorContext = factory.usingContext();
    Validator validator = validatorContext.getValidator();
    if (validator == null) {
        factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
        validator = factory.getValidator();
    }
    out.print("<p>");
    out.print("Obtained ValidatorFactory: " + factory + ".");
    out.print("</p>");
    return validator;
}
Also used : Configuration(javax.validation.Configuration) ValidatorFactory(javax.validation.ValidatorFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ValidatorContext(javax.validation.ValidatorContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GenericBootstrap(javax.validation.bootstrap.GenericBootstrap) Validator(javax.validation.Validator) PrintWriter(java.io.PrintWriter)

Example 79 with ValidatorFactory

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

the class WebContainerListener method containerEvent.

public void containerEvent(ContainerEvent event) {
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.log(Level.FINEST, LogFacade.CONTAINER_EVENT, event.getType() + "," + event.getContainer() + "," + event.getData());
    }
    String type = event.getType();
    try {
        WebModule wm = (WebModule) event.getContainer();
        if (beforeEvents.contains(type)) {
            preInvoke(wm);
            if (type.equals(ContainerEvent.BEFORE_CONTEXT_DESTROYED)) {
                try {
                    // must close the validator factory
                    if (validationNamingProxy != null) {
                        Object validatorFactory = validationNamingProxy.handle("java:comp/ValidatorFactory");
                        if (validatorFactory != null) {
                            ((ValidatorFactory) validatorFactory).close();
                        }
                    }
                } catch (NamingException exc) {
                    if (_logger.isLoggable(Level.WARNING)) {
                        _logger.log(Level.FINEST, LogFacade.EXCEPTION_GETTING_VALIDATOR_FACTORY, exc);
                    }
                }
            }
        } else if (afterEvents.contains(type)) {
            if (type.equals(ContainerEvent.AFTER_FILTER_DESTROYED) || type.equals(ContainerEvent.AFTER_CONTEXT_DESTROYED)) {
                preDestroy(event);
            }
            postInvoke(wm);
        } else if (ContainerEvent.PRE_DESTROY.equals(type)) {
            preInvoke(wm);
            preDestroy(event);
            postInvoke(wm);
        }
    } catch (Throwable t) {
        String msg = rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { type, event.getContainer() });
        _logger.log(Level.SEVERE, msg, t);
    }
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) NamingException(javax.naming.NamingException) String(java.lang.String) WebModule(com.sun.enterprise.web.WebModule)

Example 80 with ValidatorFactory

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

the class AppComposerAsJUnitRuleTest method lookupValidatorFactory.

@Test
public void lookupValidatorFactory() throws Exception {
    final ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory");
    assertNotNull(validatorFactory);
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

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