Search in sources :

Example 21 with ConfigurationPropertySource

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

the class InactiveConfigDataAccessExceptionTests method throwIfPropertyFoundWhenPropertyFoundThrowsException.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
void throwIfPropertyFoundWhenPropertyFoundThrowsException() {
    this.propertySource.setProperty("spring", "test");
    ConfigDataEnvironmentContributor contributor = mock(ConfigDataEnvironmentContributor.class);
    ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(this.propertySource);
    given(contributor.getConfigurationPropertySource()).willReturn(configurationPropertySource);
    given(contributor.getPropertySource()).willReturn((PropertySource) this.propertySource);
    given(contributor.getResource()).willReturn(this.resource);
    assertThatExceptionOfType(InactiveConfigDataAccessException.class).isThrownBy(() -> InactiveConfigDataAccessException.throwIfPropertyFound(contributor, ConfigurationPropertyName.of("spring"))).withMessage("Inactive property source 'mockProperties' imported from location 'test' " + "cannot contain property 'spring' [origin: \"spring\" from property source \"mockProperties\"]");
}
Also used : ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 22 with ConfigurationPropertySource

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

the class ProfilesTests method getDefaultWhenDefaultEnvironmentProfileAndBinderProperty.

@Test
void getDefaultWhenDefaultEnvironmentProfileAndBinderProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.profiles.default", "default");
    List<ConfigurationPropertySource> sources = new ArrayList<>();
    ConfigurationPropertySources.get(environment).forEach(sources::add);
    sources.add(new MapConfigurationPropertySource(Collections.singletonMap("spring.profiles.default", "a,b,c")));
    Binder binder = new Binder(sources);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getDefault()).containsExactly("default");
}
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 23 with ConfigurationPropertySource

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

the class ConfigurationPropertiesReportEndpoint method getPropertySource.

private PropertySource<?> getPropertySource(ConfigurationProperty configurationProperty) {
    if (configurationProperty == null) {
        return null;
    }
    ConfigurationPropertySource source = configurationProperty.getSource();
    Object underlyingSource = (source != null) ? source.getUnderlyingSource() : null;
    return (underlyingSource instanceof PropertySource<?>) ? (PropertySource<?>) underlyingSource : null;
}
Also used : ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) PropertySource(org.springframework.core.env.PropertySource)

Example 24 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project incubator-dubbo-spring-boot-project by apache.

the class BinderDubboConfigBinder method bind.

@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) {
    Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties));
    // Converts ConfigurationPropertySources
    Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources);
    // Wrap Bindable from DubboConfig instance
    Bindable bindable = Bindable.ofInstance(configurationBean);
    Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources));
    // Get BindHandler
    BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields);
    // Bind
    binder.bind("", bindable, bindHandler);
}
Also used : DubboConfigBinder(org.apache.dubbo.config.spring.context.properties.DubboConfigBinder) ConfigurationBeanBinder(com.alibaba.spring.context.config.ConfigurationBeanBinder) Binder(org.springframework.boot.context.properties.bind.Binder) MapPropertySource(org.springframework.core.env.MapPropertySource) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Bindable(org.springframework.boot.context.properties.bind.Bindable) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Aggregations

ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)24 Binder (org.springframework.boot.context.properties.bind.Binder)17 MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)11 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)4 Bindable (org.springframework.boot.context.properties.bind.Bindable)4 HashMap (java.util.HashMap)3 PlaceholdersResolver (org.springframework.boot.context.properties.bind.PlaceholdersResolver)3 MapPropertySource (org.springframework.core.env.MapPropertySource)3 PropertySource (org.springframework.core.env.PropertySource)3 ConfigurationBeanBinder (com.alibaba.spring.context.config.ConfigurationBeanBinder)2 List (java.util.List)2 Map (java.util.Map)2 DubboConfigBinder (org.apache.dubbo.config.spring.context.properties.DubboConfigBinder)2 Test (org.junit.Test)2 PropertySourcesPlaceholdersResolver (org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver)2 IgnoreErrorsBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler)2 NoUnboundElementsBindHandler (org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler)2 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)2