use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method removeSystemProperties.
/**
* Strict tests need a known set of properties so we remove system items which may be
* environment specific.
*/
private void removeSystemProperties() {
PropertySources sources = this.context.getEnvironment().getPropertySources();
sources.remove("systemProperties");
sources.remove("systemEnvironment");
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesTests method loadShouldSupportRebindableConfigurationProperties.
@Test
void loadShouldSupportRebindableConfigurationProperties() {
// gh-9160
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.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 PropertySourcesPlaceholderConfigurerTests method explicitPropertySources.
@Test
public void explicitPropertySources() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
PropertySources propertySources = new PropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
assertThat(propertySources.iterator().next()).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesEnvironment.
@Test
public void explicitPropertySourcesExcludesEnvironment() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
PropertySources propertySources = new PropertySources();
propertySources.addLast(new MockPropertySource());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
assertThat(propertySources.iterator().next()).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
}
use of cn.taketoday.core.env.PropertySources in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertySourcesTests method getWhenAttachedShouldReturnAttached.
@Test
void getWhenAttachedShouldReturnAttached() {
ConfigurableEnvironment environment = new StandardEnvironment();
PropertySources sources = environment.getPropertySources();
sources.addFirst(new MapPropertySource("test", Collections.singletonMap("a", "b")));
int expectedSize = sources.size();
ConfigurationPropertySources.attach(environment);
assertThat(ConfigurationPropertySources.get(environment)).hasSize(expectedSize);
}
Aggregations