Search in sources :

Example 1 with PropertySource

use of cn.taketoday.core.env.PropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataTests method getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone.

@Test
void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
    MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
    PropertySourceOptions propertySourceOptions = (propertySource) -> null;
    ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
    assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 2 with PropertySource

use of cn.taketoday.core.env.PropertySource 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 3 with PropertySource

use of cn.taketoday.core.env.PropertySource in project today-framework by TAKETODAY.

the class ConfigDataLoadersTests method createConfigData.

private static ConfigData createConfigData(ConfigDataLoader<?> loader, ConfigDataResource resource) {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("loader", loader);
    propertySource.setProperty("resource", resource);
    List<PropertySource<?>> propertySources = Arrays.asList(propertySource);
    return new ConfigData(propertySources);
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) PropertySource(cn.taketoday.core.env.PropertySource) MockPropertySource(cn.taketoday.mock.env.MockPropertySource)

Example 4 with PropertySource

use of cn.taketoday.core.env.PropertySource in project today-framework by TAKETODAY.

the class ConfigDataTests method getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone.

@Test
void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
    MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
    PropertySourceOptions propertySourceOptions = (propertySource) -> null;
    ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
    assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
}
Also used : Arrays(java.util.Arrays) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 5 with PropertySource

use of cn.taketoday.core.env.PropertySource 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

PropertySource (cn.taketoday.core.env.PropertySource)12 Test (org.junit.jupiter.api.Test)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 PropertySourceOptions (cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions)4 MockPropertySource (cn.taketoday.mock.env.MockPropertySource)4 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 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 MockPropertySource (cn.taketoday.core.env.MockPropertySource)2 Resource (cn.taketoday.core.io.Resource)2 Option (cn.taketoday.framework.context.config.ConfigData.Option)2 Options (cn.taketoday.framework.context.config.ConfigData.Options)2 AddedPropertySource (cn.taketoday.framework.context.config.TestConfigDataEnvironmentUpdateListener.AddedPropertySource)2 OriginTrackedResource (cn.taketoday.origin.OriginTrackedResource)2 Validator (cn.taketoday.validation.Validator)2 ValidatorAdapter (cn.taketoday.validation.beanvalidation.ValidatorAdapter)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2