Search in sources :

Example 16 with MockEnvironment

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

the class ProfilesTests method getActiveWhenNoEnvironmentProfilesAndBinderProperty.

@Test
void getActiveWhenNoEnvironmentProfilesAndBinderProperty() {
    Environment environment = new MockEnvironment();
    Binder binder = new Binder(new MapConfigurationPropertySource(Collections.singletonMap("context.profiles.active", "a,b,c")));
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).containsExactly("a", "b", "c");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 17 with MockEnvironment

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

the class ProfilesTests method iteratorWithProfileGroups.

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

Example 18 with MockEnvironment

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

the class ProfilesTests method iteratorIteratesAllActiveProfiles.

@Test
void iteratorIteratesAllActiveProfiles() {
    MockEnvironment environment = new MockEnvironment();
    environment.setActiveProfiles("a", "b", "c");
    environment.setDefaultProfiles("d", "e", "f");
    Binder binder = Binder.get(environment);
    Profiles profiles1 = new Profiles(environment, binder, null);
    Profiles profiles = profiles1;
    assertThat(profiles).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 19 with MockEnvironment

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

the class ProfilesTests method getActiveWhenNoEnvironmentProfilesAndEnvironmentPropertyInBindNotation.

@Test
void getActiveWhenNoEnvironmentProfilesAndEnvironmentPropertyInBindNotation() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active[0]", "a");
    environment.setProperty("context.profiles.active[1]", "b");
    environment.setProperty("context.profiles.active[2]", "c");
    Binder binder = Binder.get(environment);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).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 20 with MockEnvironment

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

the class ProfilesTests method isAcceptedWithGroupsReturnsTrue.

@Test
void isAcceptedWithGroupsReturnsTrue() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active", "a,b,c");
    environment.setProperty("context.profiles.group.a", "e,f");
    environment.setProperty("context.profiles.group.e", "x,y");
    environment.setDefaultProfiles("g", "h", "i");
    Binder binder = Binder.get(environment);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.isAccepted("a")).isTrue();
    assertThat(profiles.isAccepted("e")).isTrue();
    assertThat(profiles.isAccepted("g")).isFalse();
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) 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