use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpoint method sanitizeWithPropertySourceIfPresent.
private Object sanitizeWithPropertySourceIfPresent(String qualifiedKey, Object value) {
ConfigurationPropertyName currentName = getCurrentName(qualifiedKey);
ConfigurationProperty candidate = getCandidate(currentName);
PropertySource<?> propertySource = getPropertySource(candidate);
if (propertySource != null) {
SanitizableData data = new SanitizableData(propertySource, qualifiedKey, value);
return this.sanitizer.sanitize(data);
}
SanitizableData data = new SanitizableData(null, qualifiedKey, value);
return this.sanitizer.sanitize(data);
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenImportingIncludesParentOrigin.
@Test
void runWhenImportingIncludesParentOrigin() {
ConfigurableApplicationContext context = this.application.run("--spring.config.location=classpath:application-import-with-placeholder.properties");
Binder binder = Binder.get(context.getEnvironment());
List<ConfigurationProperty> properties = new ArrayList<>();
BindHandler bindHandler = new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
properties.add(context.getConfigurationProperty());
return result;
}
};
binder.bind("my.value", Bindable.of(String.class), bindHandler);
assertThat(properties).hasSize(1);
Origin origin = properties.get(0).getOrigin();
assertThat(origin.toString()).contains("application-import-with-placeholder-imported");
assertThat(origin.getParent().toString()).contains("application-import-with-placeholder");
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class InvalidConfigDataPropertyExceptionTests method createWhenNoOriginHasCorrectMessage.
@Test
void createWhenNoOriginHasCorrectMessage() {
ConfigurationProperty property = new ConfigurationProperty(this.invalid, "bad", null);
assertThat(new InvalidConfigDataPropertyException(property, false, this.replacement, this.resource)).hasMessage("Property 'invalid' imported from location 'test' is invalid and should be replaced with 'replacement'");
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class CollectionBinderTests method bindToCollectionWhenNonSequentialShouldThrowException.
@Test
void bindToCollectionWhenNonSequentialShouldThrowException() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0]", "2");
source.put("foo[1]", "1");
source.put("foo[3]", "3");
this.sources.add(source);
assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.binder.bind("foo", INTEGER_LIST)).satisfies((ex) -> {
Set<ConfigurationProperty> unbound = ((UnboundConfigurationPropertiesException) ex.getCause()).getUnboundProperties();
assertThat(unbound).hasSize(1);
ConfigurationProperty property = unbound.iterator().next();
assertThat(property.getName().toString()).isEqualTo("foo[3]");
assertThat(property.getValue()).isEqualTo("3");
});
}
use of org.springframework.boot.context.properties.source.ConfigurationProperty in project spring-boot by spring-projects.
the class BindFailureAnalyzer method analyzeGenericBindException.
private FailureAnalysis analyzeGenericBindException(BindException cause) {
StringBuilder description = new StringBuilder(String.format("%s:%n", cause.getMessage()));
ConfigurationProperty property = cause.getProperty();
buildDescription(description, property);
description.append(String.format("%n Reason: %s", getMessage(cause)));
return getFailureAnalysis(description, cause);
}
Aggregations