use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenHasPropertySourcesPlaceholderConfigurerShouldSupportRebindableConfigurationProperties.
@Test
void loadWhenHasPropertySourcesPlaceholderConfigurerShouldSupportRebindableConfigurationProperties() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new LinkedHashMap<>();
source.put("example.one", "foo");
sources.addFirst(new MapPropertySource("test-source", source));
this.context.register(PrototypePropertiesConfiguration.class);
this.context.register(PropertySourcesPlaceholderConfigurer.class);
this.context.refresh();
PrototypeBean first = this.context.getBean(PrototypeBean.class);
assertThat(first.getOne()).isEqualTo("foo");
source.put("example.one", "bar");
sources.addFirst(new MapPropertySource("extra", Collections.singletonMap("example.two", "baz")));
PrototypeBean second = this.context.getBean(PrototypeBean.class);
assertThat(second.getOne()).isEqualTo("bar");
assertThat(second.getTwo()).isEqualTo("baz");
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToConstructorParametersShouldBind.
@Test
void loadWhenBindingToConstructorParametersShouldBind() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.foo", "baz");
source.put("test.bar", "5");
sources.addLast(new MapPropertySource("test", source));
load(ConstructorParameterConfiguration.class);
ConstructorParameterProperties bean = this.context.getBean(ConstructorParameterProperties.class);
assertThat(bean.getFoo()).isEqualTo("baz");
assertThat(bean.getBar()).isEqualTo(5);
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToJavaBeanWithoutExplicitConstructorBindingOnNestedShouldUseSetterBasedBinding.
@Test
void loadWhenBindingToJavaBeanWithoutExplicitConstructorBindingOnNestedShouldUseSetterBasedBinding() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested.age", "5");
sources.addLast(new MapPropertySource("test", source));
load(JavaBeanNonDefaultConstructorPropertiesConfiguration.class);
JavaBeanNonDefaultConstructorProperties bean = this.context.getBean(JavaBeanNonDefaultConstructorProperties.class);
assertThat(bean.getNested().getAge()).isEqualTo(10);
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToJavaBeanWithNestedConstructorBindingShouldBind.
@Test
void loadWhenBindingToJavaBeanWithNestedConstructorBindingShouldBind() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested.age", "5");
sources.addLast(new MapPropertySource("test", source));
load(JavaBeanNestedConstructorBindingPropertiesConfiguration.class);
JavaBeanNestedConstructorBindingProperties bean = this.context.getBean(JavaBeanNestedConstructorBindingProperties.class);
assertThat(bean.getNested().getAge()).isEqualTo(5);
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToNestedPropertiesWithSyntheticConstructorShouldBind.
@Test
void loadWhenBindingToNestedPropertiesWithSyntheticConstructorShouldBind() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested.age", "5");
sources.addLast(new MapPropertySource("test", source));
load(SyntheticConstructorPropertiesConfiguration.class);
SyntheticNestedConstructorProperties bean = this.context.getBean(SyntheticNestedConstructorProperties.class);
assertThat(bean.getNested().getAge()).isEqualTo(5);
}
Aggregations