Search in sources :

Example 76 with FailureAnalysis

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

the class BeanCurrentlyInCreationFailureAnalyzerTests method performAnalysis.

private FailureAnalysis performAnalysis(Class<?> configuration, boolean allowCircularReferences) {
    FailureAnalysis analysis = this.analyzer.analyze(createFailure(configuration, allowCircularReferences));
    assertThat(analysis).isNotNull();
    return analysis;
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis)

Example 77 with FailureAnalysis

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

the class BeanCurrentlyInCreationFailureAnalyzerTests method cycleReferencedViaOtherBeans.

@Test
void cycleReferencedViaOtherBeans() throws IOException {
    FailureAnalysis analysis = performAnalysis(CycleReferencedViaOtherBeansConfiguration.class);
    List<String> lines = readDescriptionLines(analysis);
    assertThat(lines).hasSize(12);
    assertThat(lines.get(0)).isEqualTo("The dependencies of some of the beans in the application context form a cycle:");
    assertThat(lines.get(1)).isEqualTo("");
    assertThat(lines.get(2)).contains("refererOne (field " + RefererTwo.class.getName());
    assertThat(lines.get(3)).isEqualTo("      ↓");
    assertThat(lines.get(4)).contains("refererTwo (field " + BeanOne.class.getName());
    assertThat(lines.get(5)).isEqualTo("┌─────┐");
    assertThat(lines.get(6)).startsWith("|  one defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName());
    assertThat(lines.get(7)).isEqualTo("↑     ↓");
    assertThat(lines.get(8)).startsWith("|  two defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName());
    assertThat(lines.get(9)).isEqualTo("↑     ↓");
    assertThat(lines.get(10)).startsWith("|  three defined in " + CycleReferencedViaOtherBeansConfiguration.class.getName());
    assertThat(lines.get(11)).isEqualTo("└─────┘");
    assertThat(analysis.getAction()).isNotNull();
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 78 with FailureAnalysis

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

the class BeanCurrentlyInCreationFailureAnalyzerTests method cycleWithAutowiredFields.

@Test
void cycleWithAutowiredFields() throws IOException {
    FailureAnalysis analysis = performAnalysis(CycleWithAutowiredFields.class);
    assertThat(analysis.getDescription()).startsWith("The dependencies of some of the beans in the application context form a cycle:");
    List<String> lines = readDescriptionLines(analysis);
    assertThat(lines).hasSize(9);
    assertThat(lines.get(0)).isEqualTo("The dependencies of some of the beans in the application context form a cycle:");
    assertThat(lines.get(1)).isEqualTo("");
    assertThat(lines.get(2)).isEqualTo("┌─────┐");
    assertThat(lines.get(3)).startsWith("|  three defined in " + BeanThreeConfiguration.class.getName());
    assertThat(lines.get(4)).isEqualTo("↑     ↓");
    assertThat(lines.get(5)).startsWith("|  one defined in " + CycleWithAutowiredFields.class.getName());
    assertThat(lines.get(6)).isEqualTo("↑     ↓");
    assertThat(lines.get(7)).startsWith("|  " + BeanTwoConfiguration.class.getName() + " (field private " + BeanThree.class.getName());
    assertThat(lines.get(8)).isEqualTo("└─────┘");
    assertThat(analysis.getAction()).isNotNull();
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 79 with FailureAnalysis

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

the class BindValidationFailureAnalyzerTests method otherBindExceptionShouldReturnAnalysis.

@Test
void otherBindExceptionShouldReturnAnalysis() {
    BindException cause = new BindException(new FieldValidationFailureProperties(), "fieldValidationFailureProperties");
    cause.addError(new FieldError("test", "value", "must not be null"));
    BeanCreationException rootFailure = new BeanCreationException("bean creation failure", cause);
    FailureAnalysis analysis = new BindValidationFailureAnalyzer().analyze(rootFailure, rootFailure);
    assertThat(analysis.getDescription()).contains(failure("test.value", "null", "must not be null"));
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BindException(org.springframework.validation.BindException) FieldError(org.springframework.validation.FieldError) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 80 with FailureAnalysis

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

the class BindValidationFailureAnalyzerTests method bindExceptionWithOriginDueToValidationFailure.

@Test
void bindExceptionWithOriginDueToValidationFailure() {
    FailureAnalysis analysis = performAnalysis(FieldValidationFailureConfiguration.class, "test.foo.value=4");
    assertThat(analysis.getDescription()).contains("Origin: \"test.foo.value\" from property source \"test\"");
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.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