Search in sources :

Example 11 with PropertySource

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

the class ConfigDataLoadersTests method createConfigData.

private static ConfigData createConfigData(ConfigDataLoader<?> loader, ConfigDataResource resource) {
    MockPropertySource propertySource = new MockPropertySource();
    propertySource.setProperty("loader", loader);
    propertySource.setProperty("resource", resource);
    List<PropertySource<?>> propertySources = Arrays.asList(propertySource);
    return new ConfigData(propertySources);
}
Also used : MockPropertySource(cn.taketoday.mock.env.MockPropertySource) PropertySource(cn.taketoday.core.env.PropertySource) MockPropertySource(cn.taketoday.mock.env.MockPropertySource)

Example 12 with PropertySource

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

the class PropertySourcesPlaceholderConfigurerTests method withNonEnumerablePropertySource.

@Test
public void withNonEnumerablePropertySource() {
    StandardBeanFactory bf = new StandardBeanFactory();
    bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${foo}").getBeanDefinition());
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
    PropertySource<?> ps = new PropertySource<>("simplePropertySource", new Object()) {

        @Override
        public Object getProperty(String key) {
            return "bar";
        }
    };
    MockEnvironment env = new MockEnvironment();
    env.getPropertySources().addFirst(ps);
    ppc.setEnvironment(env);
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("bar");
}
Also used : TestBean(cn.taketoday.beans.testfixture.beans.TestBean) StandardBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory) PropertySource(cn.taketoday.core.env.PropertySource) MockPropertySource(cn.taketoday.core.env.MockPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

PropertySource (cn.taketoday.core.env.PropertySource)12 Test (org.junit.jupiter.api.Test)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 PropertySourceOptions (cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions)4 MockPropertySource (cn.taketoday.mock.env.MockPropertySource)4 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)2 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 ValidationBindHandler (cn.taketoday.context.properties.bind.validation.ValidationBindHandler)2 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)2 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)2 MockPropertySource (cn.taketoday.core.env.MockPropertySource)2 Resource (cn.taketoday.core.io.Resource)2 Option (cn.taketoday.framework.context.config.ConfigData.Option)2 Options (cn.taketoday.framework.context.config.ConfigData.Options)2 AddedPropertySource (cn.taketoday.framework.context.config.TestConfigDataEnvironmentUpdateListener.AddedPropertySource)2 OriginTrackedResource (cn.taketoday.origin.OriginTrackedResource)2 Validator (cn.taketoday.validation.Validator)2 ValidatorAdapter (cn.taketoday.validation.beanvalidation.ValidatorAdapter)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2