Search in sources :

Example 36 with Validator

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

the class BeanValidationTest method lookupValidator.

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

Example 37 with Validator

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

the class BeanValidationTest method injectionValidator.

@Test
public void injectionValidator() {
    final Validator validator = persistManager.getValidator();
    assertNotNull(validator);
}
Also used : Validator(javax.validation.Validator) Test(org.junit.Test)

Example 38 with Validator

use of javax.validation.Validator in project opennms by OpenNMS.

the class EventRestService method publishEvent.

@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public Response publishEvent(final org.opennms.netmgt.xml.event.Event event) {
    if (event.getSource() == null) {
        event.setSource("ReST");
    }
    if (event.getTime() == null) {
        event.setTime(new Date());
    }
    try {
        final Validator validator = factory.getValidator();
        final Set<ConstraintViolation<org.opennms.netmgt.xml.event.Event>> errors = validator.validate(event);
        LOG.debug("got errors: {}", errors);
        if (errors.size() > 0) {
            final StringBuilder sb = new StringBuilder("Error validating event:\n");
            for (final ConstraintViolation<?> error : errors) {
                sb.append(error.toString()).append("\n");
            }
            LOG.debug(sb.toString());
            throw getException(Status.BAD_REQUEST, errors.size() + " errors found while validating event.");
        }
        m_eventForwarder.sendNow(event);
        return Response.accepted().build();
    } catch (final Exception e) {
        throw getException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) Date(java.util.Date) Validator(javax.validation.Validator) ParseException(java.text.ParseException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with Validator

use of javax.validation.Validator in project dropwizard by dropwizard.

the class ConfigurationValidationExceptionTest method setUp.

@Before
public void setUp() throws Exception {
    assumeThat(Locale.getDefault().getLanguage(), is("en"));
    final Validator validator = BaseValidator.newValidator();
    final Set<ConstraintViolation<Example>> violations = validator.validate(new Example());
    this.e = new ConfigurationValidationException("config.yml", violations);
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) BaseValidator(io.dropwizard.validation.BaseValidator) Before(org.junit.Before)

Example 40 with Validator

use of javax.validation.Validator in project JessMA by ldcsaa.

the class HibernateBeanValidator method validate.

@Override
public Set<ConstraintViolation<Object>> validate(final Object bean, final Class<?>[] groups, final String bundle, final Locale locale) {
    ValidatorKey key = new ValidatorKey(groups, bundle, locale);
    Validator validator = validatorMap.get(key);
    if (validator == null)
        validator = tryCreateValidator(bundle, locale, key);
    return validator.validate(bean, groups);
}
Also used : Validator(javax.validation.Validator) HibernateValidator(org.hibernate.validator.HibernateValidator) BeanValidator(org.jessma.mvc.BeanValidator)

Aggregations

Validator (javax.validation.Validator)54 Test (org.junit.Test)30 ConstraintViolation (javax.validation.ConstraintViolation)26 ValidatorFactory (javax.validation.ValidatorFactory)17 InitialContext (javax.naming.InitialContext)8 ArrayList (java.util.ArrayList)5 NamingException (javax.naming.NamingException)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 HibernateValidator (org.hibernate.validator.HibernateValidator)5 File (java.io.File)4 Date (java.util.Date)4 Title (net.thucydides.core.annotations.Title)4 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)4 PodamFactory (uk.co.jemos.podam.api.PodamFactory)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashSet (java.util.HashSet)3 BeanManager (javax.enterprise.inject.spi.BeanManager)3 Context (javax.naming.Context)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 HibernateValidatorFactory (org.hibernate.validator.HibernateValidatorFactory)3