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