Search in sources :

Example 1 with StandardEnvironment

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

the class ApplicationTests method addProfilesOrderWithProperties.

@Test
void addProfilesOrderWithProperties() {
    Application application = new Application(ExampleConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    application.setAdditionalProfiles("other");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    // Active profile should win over default
    assertThat(environment.getProperty("my.property")).isEqualTo("fromotherpropertiesfile");
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 2 with StandardEnvironment

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

the class ApplicationTests method propertiesFileEnhancesEnvironment.

@Test
void propertiesFileEnhancesEnvironment() {
    Application application = new Application(ExampleConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 3 with StandardEnvironment

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

the class ApplicationTests method commandLinePropertySource.

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

Example 4 with StandardEnvironment

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

the class ApplicationTests method customEnvironment.

@Test
void customEnvironment() {
    TestApplication application = new TestApplication(ExampleConfig.class);
    application.setApplicationType(ApplicationType.NONE_WEB);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    then(application.getLoader()).should().setEnvironment(environment);
}
Also used : ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 5 with StandardEnvironment

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

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