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\"]");
}
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");
}
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;
}
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);
}
Aggregations