Search in sources :

Example 16 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 17 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 18 with FailureAnalysis

use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.

the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForObjectProviderConstructorConsumer.

@Test
public void failureAnalysisForObjectProviderConstructorConsumer() {
    FailureAnalysis failureAnalysis = analyzeFailure(createFailure(ObjectProviderConstructorConsumer.class));
    assertThat(failureAnalysis.getDescription()).startsWith("Constructor in " + ObjectProviderConstructorConsumer.class.getName() + " required a single bean, but 6 were found:");
    assertFoundBeans(failureAnalysis);
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 19 with FailureAnalysis

use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.

the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForFieldConsumer.

@Test
public void failureAnalysisForFieldConsumer() {
    FailureAnalysis failureAnalysis = analyzeFailure(createFailure(FieldConsumer.class));
    assertThat(failureAnalysis.getDescription()).startsWith("Field testBean in " + FieldConsumer.class.getName() + " required a single bean, but 6 were found:");
    assertFoundBeans(failureAnalysis);
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 20 with FailureAnalysis

use of org.springframework.boot.diagnostics.FailureAnalysis in project spring-boot by spring-projects.

the class NoUniqueBeanDefinitionFailureAnalyzerTests method failureAnalysisForXmlConsumer.

@Test
public void failureAnalysisForXmlConsumer() {
    FailureAnalysis failureAnalysis = analyzeFailure(createFailure(XmlConsumer.class));
    assertThat(failureAnalysis.getDescription()).startsWith("Parameter 0 of constructor in " + TestBeanConsumer.class.getName() + " required a single bean, but 6 were found:");
    assertFoundBeans(failureAnalysis);
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) TestBeanConsumer(org.springframework.boot.diagnostics.analyzer.nounique.TestBeanConsumer) Test(org.junit.Test)

Aggregations

FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)33 Test (org.junit.Test)27 JCacheNotFoundException (com.giffing.bucket4j.spring.boot.starter.exception.JCacheNotFoundException)1 MissingKeyFilterExpressionException (com.giffing.bucket4j.spring.boot.starter.exception.MissingKeyFilterExpressionException)1 ArrayList (java.util.ArrayList)1 ErrorMessage (org.modelmapper.spi.ErrorMessage)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 InjectionPoint (org.springframework.beans.factory.InjectionPoint)1 NoUniqueBeanDefinitionException (org.springframework.beans.factory.NoUniqueBeanDefinitionException)1 TestBeanConsumer (org.springframework.boot.diagnostics.analyzer.nounique.TestBeanConsumer)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 FieldError (org.springframework.validation.FieldError)1 ObjectError (org.springframework.validation.ObjectError)1