Search in sources :

Example 21 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getDefaultWithProfileGroups.

@Test
void getDefaultWithProfileGroups() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.default", "a,b,c");
    environment.setProperty("context.profiles.group.a", "d,e");
    Binder binder = Binder.get(environment);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getDefault()).containsExactly("a", "d", "e", "b", "c");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 22 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getActiveWhenHasAdditionalIncludesAdditional.

@Test
void getActiveWhenHasAdditionalIncludesAdditional() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active", "d,e,f");
    Binder binder = Binder.get(environment);
    Profiles profiles = new Profiles(environment, binder, Arrays.asList("a", "b", "c"));
    assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 23 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getDefaultWhenEnvironmentProfilesAndEnvironmentProperty.

@Test
void getDefaultWhenEnvironmentProfilesAndEnvironmentProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setDefaultProfiles("a", "b", "c");
    environment.setProperty("context.profiles.default", "d,e,f");
    Binder binder = Binder.get(environment);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getDefault()).containsExactly("a", "b", "c");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 24 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ApplicationTests method defaultPropertiesShouldBeMerged.

@Test
void defaultPropertiesShouldBeMerged() {
    MockEnvironment environment = new MockEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource(DefaultPropertiesPropertySource.NAME, Collections.singletonMap("bar", "foo")));
    Application application = new ApplicationBuilder(ExampleConfig.class).environment(environment).properties("baz=bing").type(ApplicationType.NONE_WEB).build();
    this.context = application.run();
    assertThat(getEnvironment().getProperty("bar")).isEqualTo("foo");
    assertThat(getEnvironment().getProperty("baz")).isEqualTo("bing");
}
Also used : ApplicationBuilder(cn.taketoday.framework.builder.ApplicationBuilder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 25 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class CloudPlatformTests method getActiveWhenHasDynoShouldReturnHeroku.

@Test
void getActiveWhenHasDynoShouldReturnHeroku() {
    Environment environment = new MockEnvironment().withProperty("DYNO", "---");
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.HEROKU);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

MockEnvironment (cn.taketoday.mock.env.MockEnvironment)132 Test (org.junit.jupiter.api.Test)118 Binder (cn.taketoday.context.properties.bind.Binder)84 Environment (cn.taketoday.core.env.Environment)24 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)16 MapConfigurationPropertySource (cn.taketoday.context.properties.source.MapConfigurationPropertySource)12 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)4 PropertySources (cn.taketoday.core.env.PropertySources)4 TestPropertySourceUtils.buildMergedTestPropertySources (cn.taketoday.test.context.support.TestPropertySourceUtils.buildMergedTestPropertySources)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 ConditionEvaluationContext (cn.taketoday.context.annotation.ConditionEvaluationContext)2 ByteArrayResource (cn.taketoday.core.io.ByteArrayResource)2 DefaultResourceLoader (cn.taketoday.core.io.DefaultResourceLoader)2 ResourceLoader (cn.taketoday.core.io.ResourceLoader)2 ApplicationBuilder (cn.taketoday.framework.builder.ApplicationBuilder)2