Search in sources :

Example 1 with MapConfigurationPropertySource

use of cn.taketoday.context.properties.source.MapConfigurationPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method getCloudPlatformWhenCloudPropertyHasBeenContributedDuringInitialLoadDeducesCloudPlatform.

@Test
void getCloudPlatformWhenCloudPropertyHasBeenContributedDuringInitialLoadDeducesCloudPlatform() {
    Environment environment = createKubernetesEnvironment();
    Binder binder = new Binder(new MapConfigurationPropertySource(Collections.singletonMap("context.main.cloud-platform", "HEROKU")));
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    assertThat(context.getCloudPlatform()).isEqualTo(CloudPlatform.HEROKU);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 2 with MapConfigurationPropertySource

use of cn.taketoday.context.properties.source.MapConfigurationPropertySource in project today-infrastructure 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 3 with MapConfigurationPropertySource

use of cn.taketoday.context.properties.source.MapConfigurationPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataPropertiesTests method isActiveAgainstBoundDataWhenProfilesDontMatch.

@Test
void isActiveAgainstBoundDataWhenProfilesDontMatch() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("context.config.activate.on-cloud-platform", "kubernetes");
    source.put("context.config.activate.on-profile", "x | z");
    Binder binder = new Binder(source);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    ConfigDataActivationContext context = new ConfigDataActivationContext(CloudPlatform.KUBERNETES, createTestProfiles());
    assertThat(properties.isActive(context)).isFalse();
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MapConfigurationPropertySource(cn.taketoday.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 4 with MapConfigurationPropertySource

use of cn.taketoday.context.properties.source.MapConfigurationPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataLocationBindHandlerTests method bindToValueObjectFromIndexedPropertiesSetsOrigin.

@Test
void bindToValueObjectFromIndexedPropertiesSetsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("test.locations[0]", "a");
    source.put("test.locations[1]", "b");
    source.put("test.locations[2]", "c");
    Binder binder = new Binder(source);
    ValueObject bound = binder.bind("test", VALUE_OBJECT, this.handler).get();
    assertThat(bound.getLocation(0)).hasToString("a");
    assertThat(bound.getLocation(0).getOrigin()).hasToString("\"test.locations[0]\" from property source \"source\"");
    assertThat(bound.getLocation(1)).hasToString("b");
    assertThat(bound.getLocation(1).getOrigin()).hasToString("\"test.locations[1]\" from property source \"source\"");
    assertThat(bound.getLocation(2)).hasToString("c");
    assertThat(bound.getLocation(2).getOrigin()).hasToString("\"test.locations[2]\" 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 5 with MapConfigurationPropertySource

use of cn.taketoday.context.properties.source.MapConfigurationPropertySource in project today-infrastructure 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

MapConfigurationPropertySource (cn.taketoday.context.properties.source.MapConfigurationPropertySource)42 Binder (cn.taketoday.context.properties.bind.Binder)40 Test (org.junit.jupiter.api.Test)38 MockEnvironment (cn.taketoday.mock.env.MockEnvironment)14 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)8 Environment (cn.taketoday.core.env.Environment)6 ArrayList (java.util.ArrayList)4 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2