Search in sources :

Example 1 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method validationCustomConfigurerTakesPrecedenceAndDoNotExposeJsr303.

@Test
public void validationCustomConfigurerTakesPrecedenceAndDoNotExposeJsr303() {
    load(WebFluxJsr303Validator.class);
    assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
    assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).isEmpty();
    assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
    Validator validator = this.context.getBean(Validator.class);
    assertThat(validator).isInstanceOf(SpringValidator.class);
    assertThat(((SpringValidator) validator).getTarget()).isSameAs(this.context.getBean(WebFluxJsr303Validator.class).validator);
}
Also used : SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 2 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method validationCustomConfigurerTakesPrecedenceAndDoNotExposeJsr303.

@Test
public void validationCustomConfigurerTakesPrecedenceAndDoNotExposeJsr303() {
    load(MvcJsr303Validator.class);
    assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
    assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).isEmpty();
    assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
    Validator validator = this.context.getBean(Validator.class);
    assertThat(validator).isInstanceOf(SpringValidator.class);
    assertThat(((SpringValidator) validator).getTarget()).isSameAs(this.context.getBean(MvcJsr303Validator.class).validator);
}
Also used : SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 3 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method validationJsr303CustomValidatorReusedAsSpringValidator.

@Test
public void validationJsr303CustomValidatorReusedAsSpringValidator() {
    load(CustomValidator.class);
    assertThat(this.context.getBeansOfType(ValidatorFactory.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(Validator.class)).hasSize(2);
    Validator validator = this.context.getBean("mvcValidator", Validator.class);
    assertThat(validator).isInstanceOf(SpringValidator.class);
    assertThat(((SpringValidator) validator).getTarget()).isSameAs(this.context.getBean(javax.validation.Validator.class));
}
Also used : SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 4 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method validationJsr303CustomValidatorReusedAsSpringValidator.

@Test
public void validationJsr303CustomValidatorReusedAsSpringValidator() {
    load(CustomValidator.class);
    assertThat(this.context.getBeansOfType(ValidatorFactory.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(Validator.class)).hasSize(2);
    Validator validator = this.context.getBean("webFluxValidator", Validator.class);
    assertThat(validator).isInstanceOf(SpringValidator.class);
    assertThat(((SpringValidator) validator).getTarget()).isSameAs(this.context.getBean(javax.validation.Validator.class));
}
Also used : SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 5 with SpringValidator

use of org.springframework.boot.autoconfigure.validation.SpringValidator 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));
}
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