use of cn.taketoday.core.env.MapPropertySource in project today-framework by TAKETODAY.
the class ServerPortInfoApplicationContextInitializer method setPortProperty.
@SuppressWarnings("unchecked")
private void setPortProperty(ConfigurableEnvironment environment, String propertyName, int port) {
PropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get("server.ports");
if (source == null) {
source = new MapPropertySource("server.ports", new HashMap<>());
sources.addFirst(source);
}
((Map<String, Object>) source.getSource()).put(propertyName, port);
}
use of cn.taketoday.core.env.MapPropertySource in project today-framework by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenBindingToNestedConstructorPropertiesWithDeducedNestedShouldBind.
@Test
// gh-18481
void loadWhenBindingToNestedConstructorPropertiesWithDeducedNestedShouldBind() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.name", "spring");
source.put("test.nested.age", "5");
sources.addLast(new MapPropertySource("test", source));
load(DeducedNestedConstructorPropertiesConfiguration.class);
DeducedNestedConstructorProperties bean = this.context.getBean(DeducedNestedConstructorProperties.class);
assertThat(bean.getName()).isEqualTo("spring");
assertThat(bean.getNested().getAge()).isEqualTo(5);
}
use of cn.taketoday.core.env.MapPropertySource in project today-framework by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenConstructorBindingWithOuterClassAndNestedAutowiredShouldThrowException.
@Test
void loadWhenConstructorBindingWithOuterClassAndNestedAutowiredShouldThrowException() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested.age", "5");
sources.addLast(new MapPropertySource("test", source));
assertThatExceptionOfType(ConfigurationPropertiesBindException.class).isThrownBy(() -> load(ConstructorBindingWithOuterClassConstructorBoundAndNestedAutowiredConfiguration.class));
}
use of cn.taketoday.core.env.MapPropertySource in project today-framework 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.MapPropertySource in project today-framework by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenConstructorBindingWithOuterClassDeducedConstructorBound.
@Test
void loadWhenConstructorBindingWithOuterClassDeducedConstructorBound() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
Map<String, Object> source = new HashMap<>();
source.put("test.nested.outer.age", "5");
sources.addLast(new MapPropertySource("test", source));
load(ConstructorBindingWithOuterClassConstructorBoundConfiguration.class);
ConstructorBindingWithOuterClassConstructorBoundProperties bean = this.context.getBean(ConstructorBindingWithOuterClassConstructorBoundProperties.class);
assertThat(bean.getNested().getOuter().getAge()).isEqualTo(5);
}
Aggregations