Search in sources :

Example 46 with FailureAnalysis

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);
}
Also used : ObjectError(org.springframework.validation.ObjectError) FieldError(org.springframework.validation.FieldError) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis)

Example 47 with FailureAnalysis

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.");
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 48 with FailureAnalysis

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();
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 49 with FailureAnalysis

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);
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 50 with FailureAnalysis

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);
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Aggregations

FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)89 Test (org.junit.jupiter.api.Test)69 Test (org.junit.Test)6 MapPropertySource (org.springframework.core.env.MapPropertySource)6 InvalidConfigurationPropertyValueException (org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException)4 MutuallyExclusiveConfigurationPropertiesException (org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException)4 BeanCreationException (org.springframework.beans.factory.BeanCreationException)3 InjectionPoint (org.springframework.beans.factory.InjectionPoint)3 LinkedHashMap (java.util.LinkedHashMap)2 FailureAnalyzer (org.springframework.boot.diagnostics.FailureAnalyzer)2 FieldError (org.springframework.validation.FieldError)2 JCacheNotFoundException (com.giffing.bucket4j.spring.boot.starter.exception.JCacheNotFoundException)1 MissingKeyFilterExpressionException (com.giffing.bucket4j.spring.boot.starter.exception.MissingKeyFilterExpressionException)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ErrorMessage (org.modelmapper.spi.ErrorMessage)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 NoUniqueBeanDefinitionException (org.springframework.beans.factory.NoUniqueBeanDefinitionException)1 LoggingFailureAnalysisReporter (org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter)1