Search in sources :

Example 31 with MapConfigurationPropertySource

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

the class ConfigDataLocationBindHandlerTests method bindToValueObjectFromCommaStringPropertyIgnoresEmptyElements.

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

Example 32 with MapConfigurationPropertySource

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

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

Example 33 with MapConfigurationPropertySource

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

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

Example 34 with MapConfigurationPropertySource

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

the class ConfigDataPropertiesTests method getImportOriginWhenBracketListReturnsOrigin.

@Test
void getImportOriginWhenBracketListReturnsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("spring.config.import[0]", "one");
    source.put("spring.config.import[1]", "two");
    source.put("spring.config.import[2]", "three");
    Binder binder = new Binder(source);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    assertThat(properties.getImports().get(1).getOrigin()).hasToString("\"spring.config.import[1]\" 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 35 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project apollo by ctripcorp.

the class ApolloClientPropertiesFactoryTest method testCreateApolloClientProperties.

@Test
public void testCreateApolloClientProperties() throws IOException {
    Map<String, String> map = new LinkedHashMap<>();
    map.put("apollo.client.extension.enabled", "true");
    map.put("apollo.client.extension.messaging-type", "long_polling");
    MapConfigurationPropertySource propertySource = new MapConfigurationPropertySource(map);
    Binder binder = new Binder(propertySource);
    ApolloClientPropertiesFactory factory = new ApolloClientPropertiesFactory();
    ApolloClientProperties apolloClientProperties = factory.createApolloClientProperties(binder, null);
    Assert.assertEquals(apolloClientProperties.getExtension().getEnabled(), true);
    Assert.assertEquals(apolloClientProperties.getExtension().getMessagingType(), ApolloClientMessagingType.LONG_POLLING);
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) ApolloClientProperties(com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

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