use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToMultiConstructorConfigurationPropertiesUsingShortcutSyntax.
@Test
// gh-18485
void loadWhenBindingToMultiConstructorConfigurationPropertiesUsingShortcutSyntax() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested[0]", "spring");
sources.addLast(new MapPropertySource("test", source));
load(MultiConstructorConfigurationPropertiesConfiguration.class);
MultiConstructorConfigurationListProperties bean = this.context.getBean(MultiConstructorConfigurationListProperties.class);
MultiConstructorConfigurationProperties nested = bean.getNested().get(0);
assertThat(nested.getName()).isEqualTo("spring");
assertThat(nested.getAge()).isEqualTo(0);
}
use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToMultiConstructorConfigurationProperties.
@Test
// gh-18485
void loadWhenBindingToMultiConstructorConfigurationProperties() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested[0].name", "spring");
source.put("test.nested[0].age", "5");
sources.addLast(new MapPropertySource("test", source));
load(MultiConstructorConfigurationPropertiesConfiguration.class);
MultiConstructorConfigurationListProperties bean = this.context.getBean(MultiConstructorConfigurationListProperties.class);
MultiConstructorConfigurationProperties nested = bean.getNested().get(0);
assertThat(nested.getName()).isEqualTo("spring");
assertThat(nested.getAge()).isEqualTo(5);
}
use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenHasUnboundElementsFromSystemEnvironmentShouldNotThrowException.
@Test
void loadWhenHasUnboundElementsFromSystemEnvironmentShouldNotThrowException() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
sources.addFirst(new MapPropertySource("test", Collections.singletonMap("com.example.foo", 5)));
sources.addLast(new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("COM_EXAMPLE_OTHER", "10")));
load(SimplePrefixedProperties.class);
SimplePrefixedProperties bean = this.context.getBean(SimplePrefixedProperties.class);
assertThat(bean.getFoo()).isEqualTo(5);
}
use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToConstructorParametersWithNotMatchingCustomDurationFormatShouldFail.
@Test
void loadWhenBindingToConstructorParametersWithNotMatchingCustomDurationFormatShouldFail() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.duration", "P12D");
sources.addLast(new MapPropertySource("test", source));
assertThatExceptionOfType(Exception.class).isThrownBy(() -> load(ConstructorParameterWithFormatConfiguration.class)).havingCause().isInstanceOf(BindException.class);
}
use of cn.taketoday.core.env.MapPropertySource 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");
}
Aggregations