Search in sources :

Example 6 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

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(org.springframework.boot.context.properties.bind.Binder) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 7 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

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(org.springframework.boot.context.properties.bind.Binder) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 8 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ConfigDataPropertiesTests method getWhenHasLegacyAndNewPropertyThrowsException.

@Test
void getWhenHasLegacyAndNewPropertyThrowsException() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("spring.profiles", "a,b");
    source.put("spring.config.activate.on-profile", "a | b");
    Binder binder = new Binder(source);
    assertThatExceptionOfType(InvalidConfigDataPropertyException.class).isThrownBy(() -> ConfigDataProperties.get(binder));
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 9 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ProfilesTests method getActiveWhenEnvironmentProfilesAndBinderPropertyShouldReturnEnvironmentProperty.

@Test
void getActiveWhenEnvironmentProfilesAndBinderPropertyShouldReturnEnvironmentProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.profiles.active", "a,b,c");
    List<ConfigurationPropertySource> sources = new ArrayList<>();
    ConfigurationPropertySources.get(environment).forEach(sources::add);
    sources.add(new MapConfigurationPropertySource(Collections.singletonMap("spring.profiles.active", "d,e,f")));
    Binder binder = new Binder(sources);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).containsExactly("a", "b", "c");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockEnvironment(org.springframework.mock.env.MockEnvironment) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) ArrayList(java.util.ArrayList) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 10 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class WebFluxPropertiesTests method bind.

private void bind(Map<String, String> map) {
    ConfigurationPropertySource source = new MapConfigurationPropertySource(map);
    new Binder(source).bind("spring.webflux", Bindable.ofInstance(this.properties));
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Aggregations

MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)35 Binder (org.springframework.boot.context.properties.bind.Binder)32 Test (org.junit.jupiter.api.Test)21 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)11 MockEnvironment (org.springframework.mock.env.MockEnvironment)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 LinkedHashMap (java.util.LinkedHashMap)3 Environment (org.springframework.core.env.Environment)3 ArrayList (java.util.ArrayList)2 ApolloClientProperties (com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties)1 DataSourceBeanCreationException (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException)1 ConfigurationPropertyNameAliases (org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases)1 Catalog (org.springframework.cloud.servicebroker.model.catalog.Catalog)1 Binder (org.springframework.cloud.stream.binder.Binder)1 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)1 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1 BindException (org.springframework.validation.BindException)1