Search in sources :

Example 1 with ValidatorAdapter

use of cn.taketoday.validation.beanvalidation.ValidatorAdapter in project today-infrastructure by TAKETODAY.

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 ValidatorAdapter(Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator());
    this.binder.bind("foo", Bindable.of(ResourceBean.class), new ValidationBindHandler(validator));
}
Also used : ValidatorAdapter(cn.taketoday.validation.beanvalidation.ValidatorAdapter) Validator(cn.taketoday.validation.Validator) ValidationBindHandler(cn.taketoday.context.properties.bind.validation.ValidationBindHandler) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySource(cn.taketoday.core.env.PropertySource) ConfigurationPropertySource(cn.taketoday.context.properties.source.ConfigurationPropertySource) MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 2 with ValidatorAdapter

use of cn.taketoday.validation.beanvalidation.ValidatorAdapter in project today-framework by TAKETODAY.

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 ValidatorAdapter(Validation.byDefaultProvider().configure().buildValidatorFactory().getValidator());
    this.binder.bind("foo", Bindable.of(ResourceBean.class), new ValidationBindHandler(validator));
}
Also used : ValidatorAdapter(cn.taketoday.validation.beanvalidation.ValidatorAdapter) Validator(cn.taketoday.validation.Validator) ValidationBindHandler(cn.taketoday.context.properties.bind.validation.ValidationBindHandler) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySource(cn.taketoday.core.env.PropertySource) ConfigurationPropertySource(cn.taketoday.context.properties.source.ConfigurationPropertySource) MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationBindHandler (cn.taketoday.context.properties.bind.validation.ValidationBindHandler)2 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)2 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)2 MapPropertySource (cn.taketoday.core.env.MapPropertySource)2 PropertySource (cn.taketoday.core.env.PropertySource)2 Validator (cn.taketoday.validation.Validator)2 ValidatorAdapter (cn.taketoday.validation.beanvalidation.ValidatorAdapter)2 Test (org.junit.jupiter.api.Test)2