Search in sources :

Example 16 with MockPropertySource

use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.

the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesLocalProperties.

@Test
@SuppressWarnings("serial")
public void explicitPropertySourcesExcludesLocalProperties() {
    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.setProperties(new Properties() {

        {
            put("my.name", "local");
        }
    });
    ppc.setIgnoreUnresolvablePlaceholders(true);
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
}
Also used : PropertySources(cn.taketoday.core.env.PropertySources) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) MockPropertySource(cn.taketoday.core.env.MockPropertySource) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

MockPropertySource (cn.taketoday.core.env.MockPropertySource)16 Test (org.junit.jupiter.api.Test)16 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)8 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)8 PropertySources (cn.taketoday.core.env.PropertySources)6 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)4 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)4 GenericApplicationContext (cn.taketoday.context.support.GenericApplicationContext)2 Properties (java.util.Properties)2