Search in sources :

Example 6 with MockEnvironment

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

the class StandardConfigDataLocationResolverTests method setup.

@BeforeEach
void setup() {
    this.environment = new MockEnvironment();
    this.environmentBinder = Binder.get(this.environment);
    this.resolver = new StandardConfigDataLocationResolver(this.environmentBinder, this.resourceLoader);
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MockEnvironment

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

the class ProfilesTests method getActiveWhenNoEnvironmentProfilesAndEnvironmentProperty.

@Test
void getActiveWhenNoEnvironmentProfilesAndEnvironmentProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active", "a,b,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 8 with MockEnvironment

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

the class ProfilesTests method getAcceptedWithProfileGroups.

@Test
void getAcceptedWithProfileGroups() {
    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.getAccepted()).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 9 with MockEnvironment

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

the class ProfilesTests method getDefaultWhenDefaultEnvironmentProfileAndBinderProperty.

@Test
void getDefaultWhenDefaultEnvironmentProfileAndBinderProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.default", "default");
    List<ConfigurationPropertySource> sources = new ArrayList<>();
    ConfigurationPropertySources.get(environment).forEach(sources::add);
    sources.add(new MapConfigurationPropertySource(Collections.singletonMap("context.profiles.default", "a,b,c")));
    Binder binder = new Binder(sources);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getDefault()).containsExactly("default");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ConfigurationPropertySource(cn.taketoday.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) ArrayList(java.util.ArrayList) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 10 with MockEnvironment

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

the class ProfilesTests method isActiveWhenNoActiveAndDefaultDoesNotContainProfileReturnsFalse.

@Test
void isActiveWhenNoActiveAndDefaultDoesNotContainProfileReturnsFalse() {
    MockEnvironment environment = new MockEnvironment();
    environment.setDefaultProfiles("d", "e", "f");
    Binder binder = Binder.get(environment);
    Profiles profiles1 = new Profiles(environment, binder, null);
    Profiles profiles = profiles1;
    assertThat(profiles.isAccepted("x")).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