Search in sources :

Example 1 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceBrokerPropertiesTest method emptyCatalog.

@Test
public void emptyCatalog() {
    Map<String, String> map = new HashMap<>();
    ConfigurationPropertySource source = new MapConfigurationPropertySource(map);
    Binder binder = new Binder(source);
    ServiceBrokerProperties properties = new ServiceBrokerProperties();
    binder.bind("spring.cloud.openservicebroker", Bindable.ofInstance(properties));
    assertThat(properties.getCatalog()).isNull();
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) HashMap(java.util.HashMap) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.Test)

Example 2 with ConfigurationPropertySource

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

the class InactiveConfigDataAccessExceptionTests method throwIfPropertyFoundWhenPropertyNotFoundDoesNothing.

@Test
void throwIfPropertyFoundWhenPropertyNotFoundDoesNothing() {
    ConfigDataEnvironmentContributor contributor = mock(ConfigDataEnvironmentContributor.class);
    ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(this.propertySource);
    given(contributor.getConfigurationPropertySource()).willReturn(configurationPropertySource);
    InactiveConfigDataAccessException.throwIfPropertyFound(contributor, ConfigurationPropertyName.of("spring"));
}
Also used : ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource 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 4 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource 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)

Example 5 with ConfigurationPropertySource

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

the class NoUnboundElementsBindHandlerTests method bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundSystemProperties.

@Test
void bindWhenUsingNoUnboundElementsHandlerShouldBindIfUnboundSystemProperties() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("example.foo", "bar");
    source.put("example.other", "baz");
    this.sources.add(source);
    this.binder = new Binder(this.sources);
    NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler(BindHandler.DEFAULT, ((configurationPropertySource) -> false));
    Example bound = this.binder.bind("example", Bindable.of(Example.class), handler).get();
    assertThat(bound.getFoo()).isEqualTo("bar");
}
Also used : Test(org.junit.jupiter.api.Test) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Bindable(org.springframework.boot.context.properties.bind.Bindable) List(java.util.List) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) BindException(org.springframework.boot.context.properties.bind.BindException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Binder(org.springframework.boot.context.properties.bind.Binder) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ArrayList(java.util.ArrayList) Binder(org.springframework.boot.context.properties.bind.Binder) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)22 Binder (org.springframework.boot.context.properties.bind.Binder)15 MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)10 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)3 Bindable (org.springframework.boot.context.properties.bind.Bindable)3 PlaceholdersResolver (org.springframework.boot.context.properties.bind.PlaceholdersResolver)3 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.Test)2 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)2 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)2 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2 PropertySource (org.springframework.core.env.PropertySource)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 ConfigurationBeanBinder (com.alibaba.spring.context.config.ConfigurationBeanBinder)1 Arrays (java.util.Arrays)1