Search in sources :

Example 6 with Origin

use of cn.taketoday.origin.Origin 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 7 with Origin

use of cn.taketoday.origin.Origin 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 8 with Origin

use of cn.taketoday.origin.Origin in project today-framework by TAKETODAY.

the class ConfigDataLocationTests method splitWhenHasOriginReturnsElementsWithOriginSet.

@Test
void splitWhenHasOriginReturnsElementsWithOriginSet() {
    Origin origin = mock(Origin.class);
    ConfigDataLocation location = ConfigDataLocation.valueOf("a;b").withOrigin(origin);
    ConfigDataLocation[] split = location.split();
    assertThat(split[0].getOrigin()).isEqualTo(origin);
    assertThat(split[1].getOrigin()).isEqualTo(origin);
}
Also used : Origin(cn.taketoday.origin.Origin) Test(org.junit.jupiter.api.Test)

Example 9 with Origin

use of cn.taketoday.origin.Origin in project today-framework by TAKETODAY.

the class ConfigurationPropertyTests method getPropertySourceShouldReturnPropertySource.

@Test
void getPropertySourceShouldReturnPropertySource() {
    Origin origin = mock(Origin.class);
    ConfigurationProperty property = ConfigurationProperty.of(this.source, NAME, "foo", origin);
    assertThat(property.getSource()).isEqualTo(this.source);
}
Also used : Origin(cn.taketoday.origin.Origin) Test(org.junit.jupiter.api.Test)

Example 10 with Origin

use of cn.taketoday.origin.Origin in project today-framework 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)

Aggregations

Origin (cn.taketoday.origin.Origin)22 Test (org.junit.jupiter.api.Test)14 ConfigurationProperty (cn.taketoday.context.properties.source.ConfigurationProperty)4 ConfigurationPropertyName (cn.taketoday.context.properties.source.ConfigurationPropertyName)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 FailureAnalysis (cn.taketoday.framework.diagnostics.FailureAnalysis)2 Nullable (cn.taketoday.lang.Nullable)2 MockOrigin (cn.taketoday.origin.MockOrigin)2 OriginProvider (cn.taketoday.origin.OriginProvider)2 TextResourceOrigin (cn.taketoday.origin.TextResourceOrigin)2 Location (cn.taketoday.origin.TextResourceOrigin.Location)2 FieldError (cn.taketoday.validation.FieldError)2 ObjectError (cn.taketoday.validation.ObjectError)2 LinkedHashSet (java.util.LinkedHashSet)2