Search in sources :

Example 1 with Bindable

use of cn.taketoday.context.properties.bind.Bindable in project today-framework by TAKETODAY.

the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenImportingIncludesParentOrigin.

@Test
void runWhenImportingIncludesParentOrigin() {
    ConfigurableApplicationContext context = this.application.run("--context.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(cn.taketoday.context.ConfigurableApplicationContext) ConfigurationProperty(cn.taketoday.context.properties.source.ConfigurationProperty) BindContext(cn.taketoday.context.properties.bind.BindContext) Origin(cn.taketoday.origin.Origin) Binder(cn.taketoday.context.properties.bind.Binder) ConfigurationPropertyName(cn.taketoday.context.properties.source.ConfigurationPropertyName) ArrayList(java.util.ArrayList) Bindable(cn.taketoday.context.properties.bind.Bindable) BindHandler(cn.taketoday.context.properties.bind.BindHandler) Test(org.junit.jupiter.api.Test)

Example 2 with Bindable

use of cn.taketoday.context.properties.bind.Bindable in project today-infrastructure by TAKETODAY.

the class ConfigDataEnvironmentPostProcessorIntegrationTests method runWhenImportingIncludesParentOrigin.

@Test
void runWhenImportingIncludesParentOrigin() {
    ConfigurableApplicationContext context = this.application.run("--context.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(cn.taketoday.context.ConfigurableApplicationContext) ConfigurationProperty(cn.taketoday.context.properties.source.ConfigurationProperty) BindContext(cn.taketoday.context.properties.bind.BindContext) Origin(cn.taketoday.origin.Origin) Binder(cn.taketoday.context.properties.bind.Binder) ConfigurationPropertyName(cn.taketoday.context.properties.source.ConfigurationPropertyName) ArrayList(java.util.ArrayList) Bindable(cn.taketoday.context.properties.bind.Bindable) BindHandler(cn.taketoday.context.properties.bind.BindHandler) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 BindContext (cn.taketoday.context.properties.bind.BindContext)2 BindHandler (cn.taketoday.context.properties.bind.BindHandler)2 Bindable (cn.taketoday.context.properties.bind.Bindable)2 Binder (cn.taketoday.context.properties.bind.Binder)2 ConfigurationProperty (cn.taketoday.context.properties.source.ConfigurationProperty)2 ConfigurationPropertyName (cn.taketoday.context.properties.source.ConfigurationPropertyName)2 Origin (cn.taketoday.origin.Origin)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2