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);
}
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);
}
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);
}
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");
}
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;
}
Aggregations