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);
}
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");
}
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);
}
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);
}
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);
}
Aggregations