use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class BindFailureAnalyzer method analyze.
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
if (CollectionUtils.isEmpty(cause.getAllErrors())) {
return null;
}
StringBuilder description = new StringBuilder(String.format("Binding to target %s failed:%n", cause.getTarget()));
for (ObjectError error : cause.getAllErrors()) {
if (error instanceof FieldError) {
FieldError fieldError = (FieldError) error;
description.append(String.format("%n Property: %s", cause.getObjectName() + "." + fieldError.getField()));
description.append(String.format("%n Value: %s", fieldError.getRejectedValue()));
}
description.append(String.format("%n Reason: %s%n", error.getDefaultMessage()));
}
return new FailureAnalysis(description.toString(), "Update your application's configuration", cause);
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class BindFailureAnalyzerTests method bindExceptionWithObjectErrorsDueToValidationFailure.
@Test
public void bindExceptionWithObjectErrorsDueToValidationFailure() throws Exception {
FailureAnalysis analysis = performAnalysis(ObjectValidationFailureConfiguration.class);
assertThat(analysis.getDescription()).contains("Reason: This object could not be bound.");
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class ValidationExceptionFailureAnalyzerTests method test.
@Test
public void test() throws Exception {
try {
new AnnotationConfigApplicationContext(TestConfiguration.class).close();
fail("Expected failure did not occur");
} catch (Exception ex) {
FailureAnalysis analysis = new ValidationExceptionFailureAnalyzer().analyze(ex);
assertThat(analysis).isNotNull();
}
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMissingCollectionType.
@Test
public void failureAnalysisForMissingCollectionType() throws Exception {
FailureAnalysis analysis = analyzeFailure(createFailure(StringCollectionConfiguration.class));
assertDescriptionConstructorMissingType(analysis, StringCollectionHandler.class, 0, String.class);
assertBeanMethodDisabled(analysis, "did not find property 'spring.string.enabled'", TestPropertyAutoConfiguration.class, "string");
assertActionMissingType(analysis, String.class);
}
use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMissingMapType.
@Test
public void failureAnalysisForMissingMapType() throws Exception {
FailureAnalysis analysis = analyzeFailure(createFailure(StringMapConfiguration.class));
assertDescriptionConstructorMissingType(analysis, StringMapHandler.class, 0, String.class);
assertBeanMethodDisabled(analysis, "did not find property 'spring.string.enabled'", TestPropertyAutoConfiguration.class, "string");
assertActionMissingType(analysis, String.class);
}
Aggregations