Search in sources :

Example 96 with Binder

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

the class ConfigDataPropertiesTests method getImportOriginWhenBracketListReturnsOrigin.

@Test
void getImportOriginWhenBracketListReturnsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("context.config.import[0]", "one");
    source.put("context.config.import[1]", "two");
    source.put("context.config.import[2]", "three");
    Binder binder = new Binder(source);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    assertThat(properties.getImports().get(1).getOrigin()).hasToString("\"context.config.import[1]\" from property source \"source\"");
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 97 with Binder

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

the class ConfigDataPropertiesTests method createTestProfiles.

private Profiles createTestProfiles() {
    MockEnvironment environment = new MockEnvironment();
    environment.setActiveProfiles("a", "b", "c");
    environment.setDefaultProfiles("d", "e", "f");
    Binder binder = Binder.get(environment);
    return new Profiles(environment, binder, null);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment)

Example 98 with Binder

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

the class ConfigDataLocationBindHandlerTests method bindToArrayFromCommaStringPropertyIgnoresEmptyElements.

@Test
void bindToArrayFromCommaStringPropertyIgnoresEmptyElements() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("locations", ",a,,b,c,");
    Binder binder = new Binder(source);
    ConfigDataLocation[] bound = binder.bind("locations", ARRAY, this.handler).get();
    String expectedLocation = "\"locations\" from property source \"source\"";
    assertThat(bound[0]).hasToString("a");
    assertThat(bound[0].getOrigin()).hasToString(expectedLocation);
    assertThat(bound[1]).hasToString("b");
    assertThat(bound[1].getOrigin()).hasToString(expectedLocation);
    assertThat(bound[2]).hasToString("c");
    assertThat(bound[2].getOrigin()).hasToString(expectedLocation);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 99 with Binder

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

the class ConfigDataLocationBindHandlerTests method bindToArrayFromCommaStringPropertySetsOrigin.

@Test
void bindToArrayFromCommaStringPropertySetsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("locations", "a,b,c");
    Binder binder = new Binder(source);
    ConfigDataLocation[] bound = binder.bind("locations", ARRAY, this.handler).get();
    String expectedLocation = "\"locations\" from property source \"source\"";
    assertThat(bound[0]).hasToString("a");
    assertThat(bound[0].getOrigin()).hasToString(expectedLocation);
    assertThat(bound[1]).hasToString("b");
    assertThat(bound[1].getOrigin()).hasToString(expectedLocation);
    assertThat(bound[2]).hasToString("c");
    assertThat(bound[2].getOrigin()).hasToString(expectedLocation);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 100 with Binder

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

the class ConfigDataLocationBindHandlerTests method bindToValueObjectFromCommaStringPropertySetsOrigin.

@Test
void bindToValueObjectFromCommaStringPropertySetsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("test.locations", "a,b,c");
    Binder binder = new Binder(source);
    ValueObject bound = binder.bind("test", VALUE_OBJECT, this.handler).get();
    String expectedLocation = "\"test.locations\" from property source \"source\"";
    assertThat(bound.getLocation(0)).hasToString("a");
    assertThat(bound.getLocation(0).getOrigin()).hasToString(expectedLocation);
    assertThat(bound.getLocation(1)).hasToString("b");
    assertThat(bound.getLocation(1).getOrigin()).hasToString(expectedLocation);
    assertThat(bound.getLocation(2)).hasToString("c");
    assertThat(bound.getLocation(2).getOrigin()).hasToString(expectedLocation);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) 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