Polish
This commit is contained in:
parent
270acd4636
commit
8aaf95b792
|
@ -167,7 +167,7 @@ class DataSourceInitializer {
|
||||||
}
|
}
|
||||||
else if (validate) {
|
else if (validate) {
|
||||||
throw new InvalidConfigurationPropertyValueException(propertyName,
|
throw new InvalidConfigurationPropertyValueException(propertyName,
|
||||||
resource, "the specified resource does not exist");
|
resource, "The specified resource does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.context.properties.source;
|
package org.springframework.boot.context.properties.source;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when a configuration property value is invalid.
|
* Exception thrown when a configuration property value is invalid.
|
||||||
*
|
*
|
||||||
|
@ -31,9 +33,19 @@ public class InvalidConfigurationPropertyValueException extends RuntimeException
|
||||||
|
|
||||||
private final String reason;
|
private final String reason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance for the specified property {@code name} and {@code value},
|
||||||
|
* including a {@code reason} why the value is invalid.
|
||||||
|
* @param name the name of the property in canonical format
|
||||||
|
* @param value the value of the property, can be {@code null}
|
||||||
|
* @param reason a human-readable text that describes why the reason is invalid.
|
||||||
|
* Starts with an upper-case and ends with a dots. Several sentences and carriage
|
||||||
|
* returns are allowed.
|
||||||
|
*/
|
||||||
public InvalidConfigurationPropertyValueException(String name, Object value,
|
public InvalidConfigurationPropertyValueException(String name, Object value,
|
||||||
String reason) {
|
String reason) {
|
||||||
super("Property " + name + " with value '" + value + "' is invalid: " + reason);
|
super("Property " + name + " with value '" + value + "' is invalid: " + reason);
|
||||||
|
Assert.notNull(name, "Name must not be null");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
|
|
|
@ -94,7 +94,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
|
||||||
private void appendReason(StringBuilder message,
|
private void appendReason(StringBuilder message,
|
||||||
InvalidConfigurationPropertyValueException cause) {
|
InvalidConfigurationPropertyValueException cause) {
|
||||||
if (StringUtils.hasText(cause.getReason())) {
|
if (StringUtils.hasText(cause.getReason())) {
|
||||||
message.append(" Validation failed for the following reason\n\n");
|
message.append(" Validation failed for the following reason:\n\n");
|
||||||
message.append(cause.getReason());
|
message.append(cause.getReason());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
||||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||||
import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter;
|
|
||||||
import org.springframework.boot.origin.Origin;
|
import org.springframework.boot.origin.Origin;
|
||||||
import org.springframework.boot.origin.OriginLookup;
|
import org.springframework.boot.origin.OriginLookup;
|
||||||
import org.springframework.core.env.EnumerablePropertySource;
|
import org.springframework.core.env.EnumerablePropertySource;
|
||||||
|
@ -43,7 +42,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||||
@Test
|
@Test
|
||||||
public void analysisWithNullEnvironment() {
|
public void analysisWithNullEnvironment() {
|
||||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||||
"test.property", "invalid", "this is not valid");
|
"test.property", "invalid", "This is not valid.");
|
||||||
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer()
|
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer()
|
||||||
.analyze(failure);
|
.analyze(failure);
|
||||||
assertThat(analysis).isNull();
|
assertThat(analysis).isNull();
|
||||||
|
@ -56,12 +55,12 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||||
this.environment.getPropertySources()
|
this.environment.getPropertySources()
|
||||||
.addFirst(OriginCapablePropertySource.get(source));
|
.addFirst(OriginCapablePropertySource.get(source));
|
||||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||||
"test.property", "invalid", "this is not valid");
|
"test.property", "invalid", "This is not valid.");
|
||||||
FailureAnalysis analysis = performAnalysis(failure);
|
FailureAnalysis analysis = performAnalysis(failure);
|
||||||
assertCommonParts(failure, analysis);
|
assertCommonParts(failure, analysis);
|
||||||
assertThat(analysis.getDescription())
|
assertThat(analysis.getDescription())
|
||||||
.contains("Validation failed for the following reason")
|
.contains("Validation failed for the following reason")
|
||||||
.contains("this is not valid")
|
.contains("This is not valid.")
|
||||||
.doesNotContain("Additionally, this property is also set");
|
.doesNotContain("Additionally, this property is also set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||||
this.environment.getPropertySources()
|
this.environment.getPropertySources()
|
||||||
.addLast(OriginCapablePropertySource.get(another));
|
.addLast(OriginCapablePropertySource.get(another));
|
||||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||||
"test.property", "invalid", "this is not valid");
|
"test.property", "invalid", "This is not valid.");
|
||||||
FailureAnalysis analysis = performAnalysis(failure);
|
FailureAnalysis analysis = performAnalysis(failure);
|
||||||
assertCommonParts(failure, analysis);
|
assertCommonParts(failure, analysis);
|
||||||
assertThat(analysis.getDescription())
|
assertThat(analysis.getDescription())
|
||||||
|
@ -106,7 +105,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||||
@Test
|
@Test
|
||||||
public void analysisWithUnknownKey() {
|
public void analysisWithUnknownKey() {
|
||||||
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
|
||||||
"test.key.not.defined", "invalid", "this is not valid");
|
"test.key.not.defined", "invalid", "This is not valid.");
|
||||||
assertThat(performAnalysis(failure)).isNull();
|
assertThat(performAnalysis(failure)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +122,7 @@ public class InvalidConfigurationPropertyValueFailureAnalyzerTests {
|
||||||
InvalidConfigurationPropertyValueException failure) {
|
InvalidConfigurationPropertyValueException failure) {
|
||||||
InvalidConfigurationPropertyValueFailureAnalyzer analyzer = new InvalidConfigurationPropertyValueFailureAnalyzer();
|
InvalidConfigurationPropertyValueFailureAnalyzer analyzer = new InvalidConfigurationPropertyValueFailureAnalyzer();
|
||||||
analyzer.setEnvironment(this.environment);
|
analyzer.setEnvironment(this.environment);
|
||||||
FailureAnalysis analysis = analyzer.analyze(failure);
|
return analyzer.analyze(failure);
|
||||||
if (analysis != null) {
|
|
||||||
new LoggingFailureAnalysisReporter().report(analysis);
|
|
||||||
}
|
|
||||||
return analysis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class OriginCapablePropertySource<T> extends EnumerablePropertySource<T>
|
static class OriginCapablePropertySource<T> extends EnumerablePropertySource<T>
|
||||||
|
|
Loading…
Reference in New Issue