use of cn.taketoday.core.env.SystemEnvironmentPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenEnvironmentPrefixSetShouldBind.
@Test
void loadWhenEnvironmentPrefixSetShouldBind() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
sources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("MY_SPRING_FOO_NAME", "Jane")));
Application application = new Application(PrefixConfiguration.class);
application.setApplicationContextFactory((webApplicationType) -> ConfigurationPropertiesTests.this.context);
application.setEnvironmentPrefix("my");
application.setEnvironment(this.context.getEnvironment());
application.run();
BasicProperties bean = this.context.getBean(BasicProperties.class);
assertThat(bean.name).isEqualTo("Jane");
}
use of cn.taketoday.core.env.SystemEnvironmentPropertySource 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.SystemEnvironmentPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadWhenUsingSystemPropertiesShouldBindToMap.
@Test
void loadWhenUsingSystemPropertiesShouldBindToMap() {
this.context.getEnvironment().getPropertySources().addLast(new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("TEST_MAP_FOO_BAR", "baz")));
load(WithComplexMapProperties.class);
WithComplexMapProperties bean = this.context.getBean(WithComplexMapProperties.class);
assertThat(bean.getMap()).containsOnlyKeys("foo");
assertThat(bean.getMap().get("foo")).containsOnly(entry("bar", "baz"));
}
use of cn.taketoday.core.env.SystemEnvironmentPropertySource in project today-infrastructure by TAKETODAY.
the class CloudPlatformTests method getEnvironmentWithEnvVariables.
private Environment getEnvironmentWithEnvVariables(Map<String, Object> environmentVariables) {
MockEnvironment environment = new MockEnvironment();
PropertySource<?> propertySource = new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, environmentVariables);
environment.getPropertySources().addFirst(propertySource);
return environment;
}
use of cn.taketoday.core.env.SystemEnvironmentPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method attachShouldAddAdapterAtBeginning.
@Test
void attachShouldAddAdapterAtBeginning() {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources sources = environment.getPropertySources();
sources.addLast(new SystemEnvironmentPropertySource("system", Collections.singletonMap("SERVER_PORT", "1234")));
sources.addLast(new MapPropertySource("config", Collections.singletonMap("server.port", "4568")));
int size = sources.size();
ConfigurationPropertySources.attach(environment);
assertThat(sources.size()).isEqualTo(size + 1);
PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
assertThat(resolver.getProperty("server.port")).isEqualTo("1234");
}
Aggregations