use of org.springframework.validation.beanvalidation.SpringValidatorAdapter in project spring-boot by spring-projects.
the class YamlConfigurationFactoryTests method missingPropertyCausesValidationError.
@Test(expected = BindException.class)
public void missingPropertyCausesValidationError() throws Exception {
this.validator = new SpringValidatorAdapter(Validation.buildDefaultValidatorFactory().getValidator());
createFoo("bar: blah");
}
use of org.springframework.validation.beanvalidation.SpringValidatorAdapter in project spring-boot by spring-projects.
the class BinderTests method bindToValidatedBeanWithResourceAndNonEnumerablePropertySource.
@Test
void bindToValidatedBeanWithResourceAndNonEnumerablePropertySource() {
ConfigurationPropertySources.from(new PropertySource<String>("test") {
@Override
public Object getProperty(String name) {
return null;
}
}).forEach(this.sources::add);
Validator validator = new SpringValidatorAdapter(Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator());
this.binder.bind("foo", Bindable.of(ResourceBean.class), new ValidationBindHandler(validator));
}
use of org.springframework.validation.beanvalidation.SpringValidatorAdapter in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method validationJsr303ValidatorExposedAsSpringValidator.
@Test
public void validationJsr303ValidatorExposedAsSpringValidator() {
load(Jsr303Validator.class);
assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
Validator validator = this.context.getBean(Validator.class);
assertThat(validator).isInstanceOf(SpringValidator.class);
SpringValidatorAdapter target = ((SpringValidator) validator).getTarget();
assertThat(new DirectFieldAccessor(target).getPropertyValue("targetValidator")).isSameAs(this.context.getBean(javax.validation.Validator.class));
}
use of org.springframework.validation.beanvalidation.SpringValidatorAdapter in project spring-boot by spring-projects.
the class WebFluxAnnotationAutoConfigurationTests method validationJsr303ValidatorExposedAsSpringValidator.
@Test
public void validationJsr303ValidatorExposedAsSpringValidator() {
load(Jsr303Validator.class);
assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
Validator validator = this.context.getBean(Validator.class);
assertThat(validator).isInstanceOf(SpringValidator.class);
SpringValidatorAdapter target = ((SpringValidator) validator).getTarget();
assertThat(new DirectFieldAccessor(target).getPropertyValue("targetValidator")).isSameAs(this.context.getBean(javax.validation.Validator.class));
}
use of org.springframework.validation.beanvalidation.SpringValidatorAdapter in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method testMissingPropertyCausesValidationError.
@Test(expected = BindException.class)
public void testMissingPropertyCausesValidationError() throws Exception {
this.validator = new SpringValidatorAdapter(Validation.buildDefaultValidatorFactory().getValidator());
createFoo("bar: blah");
}
Aggregations