Search in sources :

Example 1 with BindContext

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

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)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 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)1 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)1 Origin (org.springframework.boot.origin.Origin)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1