use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForNoMatchName.
@Test
void failureAnalysisForNoMatchName() {
FailureAnalysis analysis = analyzeFailure(createFailure(StringNameHandler.class));
assertThat(analysis.getDescription()).startsWith(String.format("Constructor in %s required a bean named '%s' that could not be found", StringNameHandler.class.getName(), "test-string"));
assertThat(analysis.getAction()).startsWith(String.format("Consider defining a bean named '%s' in your configuration.", "test-string"));
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMultipleBeans.
@Test
void failureAnalysisForMultipleBeans() {
FailureAnalysis analysis = analyzeFailure(new NoUniqueBeanDefinitionException(String.class, 2, "Test"));
assertThat(analysis).isNull();
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
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 org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class ConfigDataNotFoundFailureAnalyzerTests method analyzeWhenConfigDataResourceWithLocationNotFoundException.
@Test
void analyzeWhenConfigDataResourceWithLocationNotFoundException() {
ConfigDataLocation location = ConfigDataLocation.of("test");
ConfigDataResource resource = new TestConfigDataResource("myresource");
ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(resource).withLocation(location);
FailureAnalysis result = this.analyzer.analyze(exception);
assertThat(result.getDescription()).isEqualTo("Config data resource 'myresource' via location 'test' does not exist");
assertThat(result.getAction()).isEqualTo("Check that the value 'test' is correct, or prefix it with 'optional:'");
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class ConfigDataNotFoundFailureAnalyzerTests method analyzeWhenConfigDataLocationWithOriginNotFoundException.
@Test
void analyzeWhenConfigDataLocationWithOriginNotFoundException() {
ConfigDataLocation location = ConfigDataLocation.of("test").withOrigin(new TestOrigin("origin"));
ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location);
FailureAnalysis result = this.analyzer.analyze(exception);
assertThat(result.getDescription()).isEqualTo("Config data location 'test' does not exist");
assertThat(result.getAction()).isEqualTo("Check that the value 'test' at origin is correct, or prefix it with 'optional:'");
}
Aggregations