Search in sources :

Example 11 with ConfigurableEnvironment

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

the class ApplicationTests method addProfiles.

@Test
void addProfiles() {
    Application application = new Application(ExampleConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    application.setAdditionalProfiles("foo");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    assertThat(environment.acceptsProfiles(Profiles.of("foo"))).isTrue();
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 12 with ConfigurableEnvironment

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

the class ApplicationTests method disableCommandLinePropertySource.

@Test
void disableCommandLinePropertySource() {
    Application application = new Application(ExampleConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    application.setAddCommandLineProperties(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run("--foo=bar");
    assertThat(environment).doesNotHave(matchingPropertySource(PropertySource.class, "commandLineArgs"));
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) PropertySource(cn.taketoday.core.env.PropertySource) CommandLinePropertySource(cn.taketoday.core.env.CommandLinePropertySource) MapPropertySource(cn.taketoday.core.env.MapPropertySource) CompositePropertySource(cn.taketoday.core.env.CompositePropertySource) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurableEnvironment

use of cn.taketoday.core.env.ConfigurableEnvironment 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);
}
Also used : PropertySources(cn.taketoday.core.env.PropertySources) 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 14 with ConfigurableEnvironment

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

the class ConfigurationPropertySourcesTests method attachShouldAddAdapterAtBeginning.

@Test
void attachShouldAddAdapterAtBeginning() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    PropertySources sources = environment.getPropertySources();
    sources.addLast(new SystemEnvironmentPropertySource("system", Collections.singletonMap("SERVER_PORT", "1234")));
    sources.addLast(new MapPropertySource("config", Collections.singletonMap("server.port", "4568")));
    int size = sources.size();
    ConfigurationPropertySources.attach(environment);
    assertThat(sources.size()).isEqualTo(size + 1);
    PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
    assertThat(resolver.getProperty("server.port")).isEqualTo("1234");
}
Also used : PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) SystemEnvironmentPropertySource(cn.taketoday.core.env.SystemEnvironmentPropertySource) PropertySources(cn.taketoday.core.env.PropertySources) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertyResolver(cn.taketoday.core.env.PropertyResolver) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 15 with ConfigurableEnvironment

use of cn.taketoday.core.env.ConfigurableEnvironment 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)

Aggregations

ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)94 Test (org.junit.jupiter.api.Test)82 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)42 PropertySources (cn.taketoday.core.env.PropertySources)22 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)20 MapPropertySource (cn.taketoday.core.env.MapPropertySource)16 MockEnvironment (cn.taketoday.mock.env.MockEnvironment)8 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)6 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)4 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)4 ApplicationContext (cn.taketoday.context.ApplicationContext)4 ClassPathScanningCandidateComponentProvider (cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider)4 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)4 CommandLinePropertySource (cn.taketoday.core.env.CommandLinePropertySource)4 CompositePropertySource (cn.taketoday.core.env.CompositePropertySource)4 PropertiesPropertySource (cn.taketoday.core.env.PropertiesPropertySource)4 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Properties (java.util.Properties)4