Search in sources :

Example 21 with Validator

use of javax.validation.Validator in project podam by devopsfolks.

the class ValidatedPojoTest method whenMaxLengthIsNotSpecifiedInSizeAnnotationPodamShouldAssignASensibleDefault.

@Test
@Title("When the @Size annotation doesn't have a max length specified, Podam should assign a sensible value")
public void whenMaxLengthIsNotSpecifiedInSizeAnnotationPodamShouldAssignASensibleDefault() throws Exception {
    PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
    ValidationPojoForStringWithSizeAndNoMax pojo = podamInvocationSteps.whenIInvokeTheFactoryForClass(ValidationPojoForStringWithSizeAndNoMax.class, podamFactory);
    podamValidationSteps.theObjectShouldNotBeNull(pojo);
    Validator validator = podamFactorySteps.givenAJavaxValidator();
    validatorSteps.thePojoShouldNotViolateAnyValidations(validator, pojo);
}
Also used : PodamFactory(uk.co.jemos.podam.api.PodamFactory) ValidationPojoForStringWithSizeAndNoMax(uk.co.jemos.podam.test.dto.ValidationPojoForStringWithSizeAndNoMax) Validator(javax.validation.Validator) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 22 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 23 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)

Example 24 with Validator

use of javax.validation.Validator in project spring-petclinic by spring-projects.

the class ValidatorTests method shouldNotValidateWhenFirstNameEmpty.

@Test
public void shouldNotValidateWhenFirstNameEmpty() {
    LocaleContextHolder.setLocale(Locale.ENGLISH);
    Person person = new Person();
    person.setFirstName("");
    person.setLastName("smith");
    Validator validator = createValidator();
    Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);
    assertThat(constraintViolations.size()).isEqualTo(1);
    ConstraintViolation<Person> violation = constraintViolations.iterator().next();
    assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
    assertThat(violation.getMessage()).isEqualTo("may not be empty");
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 25 with Validator

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

the class KeywhizTestRunner method createInjector.

static Injector createInjector() {
    KeywhizService service = new KeywhizService();
    Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
    service.initialize(bootstrap);
    File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
    KeywhizConfig config;
    try {
        config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile);
    } catch (IOException | ConfigurationException e) {
        throw Throwables.propagate(e);
    }
    Environment environment = new Environment(service.getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader());
    Injector injector = Guice.createInjector(new ServiceModule(config, environment));
    service.setInjector(injector);
    return injector;
}
Also used : IOException(java.io.IOException) ConfigurationException(io.dropwizard.configuration.ConfigurationException) Injector(com.google.inject.Injector) ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment) File(java.io.File) Validator(javax.validation.Validator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Validator (javax.validation.Validator)42 Test (org.junit.Test)25 ConstraintViolation (javax.validation.ConstraintViolation)19 ValidatorFactory (javax.validation.ValidatorFactory)13 InitialContext (javax.naming.InitialContext)8 ArrayList (java.util.ArrayList)5 HibernateValidator (org.hibernate.validator.HibernateValidator)5 File (java.io.File)4 NamingException (javax.naming.NamingException)4 ConstraintViolationException (javax.validation.ConstraintViolationException)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 Context (javax.naming.Context)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 HibernateValidatorFactory (org.hibernate.validator.HibernateValidatorFactory)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2