Search in sources :

Example 1 with Origin

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

the class ConfigDataLocationTests method getOriginWhenWithOriginReturnsOrigin.

@Test
void getOriginWhenWithOriginReturnsOrigin() {
    Origin origin = mock(Origin.class);
    ConfigDataLocation location = ConfigDataLocation.valueOf("test").withOrigin(origin);
    assertThat(location.getOrigin()).isSameAs(origin);
}
Also used : Origin(cn.taketoday.origin.Origin) Test(org.junit.jupiter.api.Test)

Example 2 with Origin

use of cn.taketoday.origin.Origin in project today-infrastructure 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 3 with Origin

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

the class ConfigDataNotFoundFailureAnalyzer method analyze.

@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataNotFoundException cause) {
    ConfigDataLocation location = getLocation(cause);
    Origin origin = Origin.from(location);
    String message = String.format("Config data %s does not exist", cause.getReferenceDescription());
    StringBuilder action = new StringBuilder("Check that the value ");
    if (location != null) {
        action.append(String.format("'%s' ", location));
    }
    if (origin != null) {
        action.append(String.format("at %s ", origin));
    }
    action.append("is correct");
    if (location != null && !location.isOptional()) {
        action.append(String.format(", or prefix it with '%s'", ConfigDataLocation.OPTIONAL_PREFIX));
    }
    return new FailureAnalysis(message, action.toString(), cause);
}
Also used : Origin(cn.taketoday.origin.Origin) FailureAnalysis(cn.taketoday.framework.diagnostics.FailureAnalysis)

Example 4 with Origin

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

the class BindValidationFailureAnalyzer method appendFieldError.

private void appendFieldError(StringBuilder description, FieldError error) {
    Origin origin = Origin.from(error);
    description.append(String.format("%n    Property: %s", error.getObjectName() + "." + error.getField()));
    description.append(String.format("%n    Value: %s", error.getRejectedValue()));
    if (origin != null) {
        description.append(String.format("%n    Origin: %s", origin));
    }
}
Also used : Origin(cn.taketoday.origin.Origin)

Example 5 with Origin

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

the class OriginTrackedPropertiesLoader method loadValue.

private OriginTrackedValue loadValue(StringBuilder buffer, CharacterReader reader, boolean splitLists) throws IOException {
    buffer.setLength(0);
    while (reader.isWhiteSpace() && !reader.isEndOfLine()) {
        reader.read();
    }
    Location location = reader.getLocation();
    while (!reader.isEndOfLine() && !(splitLists && reader.isListDelimiter())) {
        buffer.append(reader.getCharacter());
        reader.read();
    }
    Origin origin = new TextResourceOrigin(this.resource, location);
    return OriginTrackedValue.of(buffer.toString(), origin);
}
Also used : Origin(cn.taketoday.origin.Origin) TextResourceOrigin(cn.taketoday.origin.TextResourceOrigin) TextResourceOrigin(cn.taketoday.origin.TextResourceOrigin) Location(cn.taketoday.origin.TextResourceOrigin.Location)

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