Search in sources :

Example 1 with ConfigurationPropertyName

use of cn.taketoday.context.properties.source.ConfigurationPropertyName in project today-infrastructure by TAKETODAY.

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(cn.taketoday.context.properties.source.ConfigurationPropertyName)

Example 2 with ConfigurationPropertyName

use of cn.taketoday.context.properties.source.ConfigurationPropertyName in project today-infrastructure by TAKETODAY.

the class ValidationErrorsTests method getErrorsShouldAdaptFieldErrorsToBeOriginProviders.

@Test
void getErrorsShouldAdaptFieldErrorsToBeOriginProviders() {
    Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
    ConfigurationPropertyName name1 = ConfigurationPropertyName.of("foo.bar");
    Origin origin1 = MockOrigin.of("line1");
    boundProperties.add(new ConfigurationProperty(name1, "boot", origin1));
    ConfigurationPropertyName name2 = ConfigurationPropertyName.of("foo.baz.bar");
    Origin origin2 = MockOrigin.of("line2");
    boundProperties.add(new ConfigurationProperty(name2, "boot", origin2));
    List<ObjectError> allErrors = new ArrayList<>();
    allErrors.add(new FieldError("objectname", "bar", "message"));
    ValidationErrors errors = new ValidationErrors(ConfigurationPropertyName.of("foo.baz"), boundProperties, allErrors);
    assertThat(Origin.from(errors.getAllErrors().get(0))).isEqualTo(origin2);
}
Also used : ConfigurationProperty(cn.taketoday.context.properties.source.ConfigurationProperty) LinkedHashSet(java.util.LinkedHashSet) MockOrigin(cn.taketoday.origin.MockOrigin) Origin(cn.taketoday.origin.Origin) ConfigurationPropertyName(cn.taketoday.context.properties.source.ConfigurationPropertyName) ObjectError(cn.taketoday.validation.ObjectError) ArrayList(java.util.ArrayList) FieldError(cn.taketoday.validation.FieldError) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationPropertyName

use of cn.taketoday.context.properties.source.ConfigurationPropertyName in project today-infrastructure by TAKETODAY.

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(cn.taketoday.context.properties.source.ConfigurationPropertyName) MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) ValidationBindHandler(cn.taketoday.context.properties.bind.validation.ValidationBindHandler) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurationPropertyName

use of cn.taketoday.context.properties.source.ConfigurationPropertyName 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 5 with ConfigurationPropertyName

use of cn.taketoday.context.properties.source.ConfigurationPropertyName in project today-framework by TAKETODAY.

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(cn.taketoday.context.properties.source.ConfigurationPropertyName) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationPropertyName (cn.taketoday.context.properties.source.ConfigurationPropertyName)13 Test (org.junit.jupiter.api.Test)8 ConfigurationProperty (cn.taketoday.context.properties.source.ConfigurationProperty)4 Origin (cn.taketoday.origin.Origin)4 ArrayList (java.util.ArrayList)4 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 ValidationBindHandler (cn.taketoday.context.properties.bind.validation.ValidationBindHandler)2 IterableConfigurationPropertySource (cn.taketoday.context.properties.source.IterableConfigurationPropertySource)2 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)2 MockOrigin (cn.taketoday.origin.MockOrigin)2 FieldError (cn.taketoday.validation.FieldError)2 ObjectError (cn.taketoday.validation.ObjectError)2 LinkedHashSet (java.util.LinkedHashSet)2