Search in sources :

Example 6 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator 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));
}
Also used : SpringValidatorAdapter(org.springframework.validation.beanvalidation.SpringValidatorAdapter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SpringValidator (org.springframework.boot.autoconfigure.validation.SpringValidator)6 Validator (org.springframework.validation.Validator)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 SpringValidatorAdapter (org.springframework.validation.beanvalidation.SpringValidatorAdapter)2