Search in sources :

Example 1 with Validator

use of org.springframework.validation.Validator in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method simpValidatorCustom.

@Test
public void simpValidatorCustom() {
    final Validator validator = mock(Validator.class);
    AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {

        @Override
        public Validator getValidator() {
            return validator;
        }
    };
    assertSame(validator, config.simpValidator());
}
Also used : Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 2 with Validator

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

the class WebFluxAnnotationAutoConfigurationTests method validationCustomConfigurerTakesPrecedence.

@Test
public void validationCustomConfigurerTakesPrecedence() {
    load(WebFluxValidator.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).isSameAs(this.context.getBean(WebFluxValidator.class).validator);
}
Also used : SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Example 3 with Validator

use of org.springframework.validation.Validator 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 4 with Validator

use of org.springframework.validation.Validator 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 5 with Validator

use of org.springframework.validation.Validator 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)

Aggregations

Validator (org.springframework.validation.Validator)19 Test (org.junit.Test)15 SpringValidator (org.springframework.boot.autoconfigure.validation.SpringValidator)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Bean (org.springframework.context.annotation.Bean)3 WebExchangeDataBinder (org.springframework.web.bind.support.WebExchangeDataBinder)3 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ConversionService (org.springframework.core.convert.ConversionService)2 SpringValidatorAdapter (org.springframework.validation.beanvalidation.SpringValidatorAdapter)2 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)2 WebBindingInitializer (org.springframework.web.bind.support.WebBindingInitializer)2 BindingContext (org.springframework.web.reactive.BindingContext)2 FAIL_ON_UNKNOWN_PROPERTIES (com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)1 DEFAULT_VIEW_INCLUSION (com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 List (java.util.List)1 Locale (java.util.Locale)1