use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method systemPropertyBindingFailuresAreIgnored.
@Test
public void systemPropertyBindingFailuresAreIgnored() throws Exception {
setupFactory();
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
propertySource.setProperty("doesNotExist", "foo");
propertySource.setProperty("name", "bar");
propertySources.addFirst(propertySource);
this.factory.setPropertySources(propertySources);
this.factory.setIgnoreUnknownFields(false);
this.factory.afterPropertiesSet();
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method systemEnvironmentBindingFailuresAreIgnored.
@Test
public void systemEnvironmentBindingFailuresAreIgnored() throws Exception {
setupFactory();
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
propertySource.setProperty("doesNotExist", "foo");
propertySource.setProperty("name", "bar");
propertySources.addFirst(propertySource);
this.factory.setPropertySources(propertySources);
this.factory.setIgnoreUnknownFields(false);
this.factory.afterPropertiesSet();
Foo foo = this.factory.getObject();
assertThat(foo.name).isEqualTo("bar");
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method systemEnvironmentNoResolvePlaceholders.
@Test
public void systemEnvironmentNoResolvePlaceholders() throws Exception {
setupFactory();
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
propertySource.setProperty("name", "${foo.name:bar}");
propertySources.addFirst(propertySource);
this.factory.setPropertySources(propertySources);
this.factory.setResolvePlaceholders(false);
this.factory.afterPropertiesSet();
Foo foo = this.factory.getObject();
assertThat(foo.name).isEqualTo("${foo.name:bar}");
}
use of org.springframework.core.env.MutablePropertySources in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySources.
@Test
public void explicitPropertySources() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
use of org.springframework.core.env.MutablePropertySources in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesEnvironment.
@Test
public void explicitPropertySourcesExcludesEnvironment() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
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(), equalTo("${my.name}"));
assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
Aggregations