Search in sources :

Example 16 with Binder

use of cn.taketoday.context.properties.bind.Binder in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getDefaultWhenEnvironmentProfilesInBindNotationAndEnvironmentPropertyReturnsBoth.

@Test
void getDefaultWhenEnvironmentProfilesInBindNotationAndEnvironmentPropertyReturnsBoth() {
    MockEnvironment environment = new MockEnvironment();
    environment.setDefaultProfiles("a", "b", "c");
    environment.setProperty("context.profiles.default[0]", "d");
    environment.setProperty("context.profiles.default[1]", "e");
    environment.setProperty("context.profiles.default[2]", "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 17 with Binder

use of cn.taketoday.context.properties.bind.Binder in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getActiveWithProfileGroups.

@Test
void getActiveWithProfileGroups() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.active", "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.getActive()).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 18 with Binder

use of cn.taketoday.context.properties.bind.Binder in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getDefaultWhenNoEnvironmentProfilesAndEnvironmentPropertyInBindNotation.

@Test
void getDefaultWhenNoEnvironmentProfilesAndEnvironmentPropertyInBindNotation() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("context.profiles.default[0]", "a");
    environment.setProperty("context.profiles.default[1]", "b");
    environment.setProperty("context.profiles.default[2]", "c");
    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 19 with Binder

use of cn.taketoday.context.properties.bind.Binder in project today-infrastructure by TAKETODAY.

the class ProfilesTests method getDefaultWhenNoEnvironmentProfilesAndNoPropertyReturnsEmptyArray.

@Test
void getDefaultWhenNoEnvironmentProfilesAndNoPropertyReturnsEmptyArray() {
    Environment environment = new MockEnvironment();
    Binder binder = Binder.get(environment);
    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) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) Test(org.junit.jupiter.api.Test)

Example 20 with Binder

use of cn.taketoday.context.properties.bind.Binder 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)

Aggregations

Binder (cn.taketoday.context.properties.bind.Binder)169 Test (org.junit.jupiter.api.Test)148 MockEnvironment (cn.taketoday.mock.env.MockEnvironment)86 MapConfigurationPropertySource (cn.taketoday.context.properties.source.MapConfigurationPropertySource)40 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)28 MockPropertySource (cn.taketoday.mock.env.MockPropertySource)16 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)14 Environment (cn.taketoday.core.env.Environment)14 ArrayList (java.util.ArrayList)10 BeforeEach (org.junit.jupiter.api.BeforeEach)8 BindHandler (cn.taketoday.context.properties.bind.BindHandler)6 Bindable (cn.taketoday.context.properties.bind.Bindable)6 ConfigurationPropertyName (cn.taketoday.context.properties.source.ConfigurationPropertyName)6 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)6 BindContext (cn.taketoday.context.properties.bind.BindContext)4 List (java.util.List)4 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 BindException (cn.taketoday.context.properties.bind.BindException)2 PlaceholdersResolver (cn.taketoday.context.properties.bind.PlaceholdersResolver)2 ConfigurationProperty (cn.taketoday.context.properties.source.ConfigurationProperty)2