Search in sources :

Example 11 with StandardEnvironment

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

the class ConfigurationPropertySourcesTests method fromPropertySourceShouldFlattenPropertySources.

@Test
void fromPropertySourceShouldFlattenPropertySources() {
    StandardEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource("foo", Collections.singletonMap("foo", "bar")));
    environment.getPropertySources().addFirst(new MapPropertySource("far", Collections.singletonMap("far", "far")));
    PropertySources sources = new PropertySources();
    sources.addFirst(new PropertySource<Environment>("env", environment) {

        @Override
        public String getProperty(String key) {
            return this.source.getProperty(key);
        }
    });
    sources.addLast(new MapPropertySource("baz", Collections.singletonMap("baz", "barf")));
    Iterable<ConfigurationPropertySource> configurationSources = ConfigurationPropertySources.from(sources);
    assertThat(configurationSources.iterator()).toIterable().hasSize(5);
}
Also used : PropertySources(cn.taketoday.core.env.PropertySources) MapPropertySource(cn.taketoday.core.env.MapPropertySource) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) Environment(cn.taketoday.core.env.Environment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 12 with StandardEnvironment

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

the class ConfigurationPropertySourcesTests method attachShouldReattachInMergedSetup.

@Test
void attachShouldReattachInMergedSetup() {
    ConfigurableEnvironment parent = new StandardEnvironment();
    ConfigurationPropertySources.attach(parent);
    ConfigurableEnvironment child = new StandardEnvironment();
    child.merge(parent);
    child.getPropertySources().addLast(new MapPropertySource("config", Collections.singletonMap("my.example_property", "1234")));
    ConfigurationPropertySources.attach(child);
    assertThat(child.getProperty("my.example-property")).isEqualTo("1234");
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 13 with StandardEnvironment

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

the class ConfigurationPropertyCachingTests method setup.

@BeforeEach
void setup() {
    this.environment = new StandardEnvironment();
    this.propertySource = new MapPropertySource("test", Collections.singletonMap("spring", "boot"));
    this.environment.getPropertySources().addLast(this.propertySource);
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with StandardEnvironment

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

the class ResourceArrayPropertyEditorTests method strictSystemPropertyReplacementWithUnresolvablePlaceholder.

@Test
void strictSystemPropertyReplacementWithUnresolvablePlaceholder() {
    PropertyEditor editor = new ResourceArrayPropertyEditor(new PathMatchingPatternResourceLoader(), new StandardEnvironment(), false);
    System.setProperty("test.prop", "foo");
    try {
        assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("${test.prop}-${bar}"));
    } finally {
        System.getProperties().remove("test.prop");
    }
}
Also used : PropertyEditor(java.beans.PropertyEditor) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 15 with StandardEnvironment

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

the class StandardEnvironmentTests method loadProperties.

@Test
void loadProperties() throws IOException {
    ConfigurableEnvironment environment = new StandardEnvironment();
    PropertySources propertySources = environment.getPropertySources();
    Properties properties = PropertiesUtils.loadProperties(ResourceUtils.getResource("classpath:info.properties"));
    propertySources.addLast(new PropertiesPropertySource("info", properties));
    assert "https://taketoday.cn".equals(environment.getProperty("site.host"));
}
Also used : PropertySources(cn.taketoday.core.env.PropertySources) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) PropertiesPropertySource(cn.taketoday.core.env.PropertiesPropertySource) Properties(java.util.Properties) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)96 Test (org.junit.jupiter.api.Test)88 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)46 MapPropertySource (cn.taketoday.core.env.MapPropertySource)24 PropertySources (cn.taketoday.core.env.PropertySources)18 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)8 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)8 Environment (cn.taketoday.core.env.Environment)6 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)6 StandardServletEnvironment (cn.taketoday.web.context.support.StandardServletEnvironment)6 LinkedHashMap (java.util.LinkedHashMap)6 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)4 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)4 ClassPathScanningCandidateComponentProvider (cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider)4 MockEnvironment (cn.taketoday.context.support.MockEnvironment)4 AbstractEnvironment (cn.taketoday.core.env.AbstractEnvironment)4 CommandLinePropertySource (cn.taketoday.core.env.CommandLinePropertySource)4 CompositePropertySource (cn.taketoday.core.env.CompositePropertySource)4 MockPropertySource (cn.taketoday.core.env.MockPropertySource)4 PropertyResolver (cn.taketoday.core.env.PropertyResolver)4