Search in sources :

Example 1 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName 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);
}
Also used : ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) SanitizableData(org.springframework.boot.actuate.endpoint.SanitizableData)

Example 2 with ConfigurationPropertyName

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

the class IndexedElementsBinder method bindIndexed.

private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root, AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType elementType) {
    MultiValueMap<String, ConfigurationPropertyName> knownIndexedChildren = getKnownIndexedChildren(source, root);
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        ConfigurationPropertyName name = root.append((i != 0) ? "[" + i + "]" : INDEX_ZERO);
        Object value = elementBinder.bind(name, Bindable.of(elementType), source);
        if (value == null) {
            break;
        }
        knownIndexedChildren.remove(name.getLastElement(Form.UNIFORM));
        collection.get().add(value);
    }
    assertNoUnboundChildren(source, knownIndexedChildren);
}
Also used : ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName)

Example 3 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName 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");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) BindContext(org.springframework.boot.context.properties.bind.BindContext) Origin(org.springframework.boot.origin.Origin) Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) ArrayList(java.util.ArrayList) Bindable(org.springframework.boot.context.properties.bind.Bindable) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurationPropertyName

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

the class BinderTests method bindToJavaBeanWhenHandlerOnStartReturnsNullShouldReturnUnbound.

@Test
void bindToJavaBeanWhenHandlerOnStartReturnsNullShouldReturnUnbound() {
    // gh-18129
    this.sources.add(new MockConfigurationPropertySource("foo.value", "bar"));
    BindResult<JavaBean> result = this.binder.bind("foo", Bindable.of(JavaBean.class), new BindHandler() {

        @Override
        public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) {
            return null;
        }
    });
    assertThat(result.isBound()).isFalse();
}
Also used : ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ValidationBindHandler(org.springframework.boot.context.properties.bind.validation.ValidationBindHandler) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigurationPropertyName

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

the class ValidationErrorsTests method getNameShouldReturnName.

@Test
void getNameShouldReturnName() {
    ConfigurationPropertyName name = NAME;
    ValidationErrors errors = new ValidationErrors(name, Collections.emptySet(), Collections.emptyList());
    assertThat((Object) errors.getName()).isEqualTo(name);
}
Also used : ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)9 Test (org.junit.jupiter.api.Test)4 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)4 ArrayList (java.util.ArrayList)2 SanitizableData (org.springframework.boot.actuate.endpoint.SanitizableData)2 Origin (org.springframework.boot.origin.Origin)2 LinkedHashSet (java.util.LinkedHashSet)1 BindContext (org.springframework.boot.context.properties.bind.BindContext)1 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)1 Bindable (org.springframework.boot.context.properties.bind.Bindable)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)1 IterableConfigurationPropertySource (org.springframework.boot.context.properties.source.IterableConfigurationPropertySource)1 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)1 MockOrigin (org.springframework.boot.origin.MockOrigin)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 FieldError (org.springframework.validation.FieldError)1 ObjectError (org.springframework.validation.ObjectError)1