Search in sources :

Example 1 with FailureAnalysis

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

the class BeanCurrentlyInCreationFailureAnalyzer method analyze.

@Override
protected FailureAnalysis analyze(Throwable rootFailure, BeanCurrentlyInCreationException cause) {
    List<BeanInCycle> cycle = new ArrayList<>();
    Throwable candidate = rootFailure;
    int cycleStart = -1;
    while (candidate != null) {
        BeanInCycle beanInCycle = BeanInCycle.get(candidate);
        if (beanInCycle != null) {
            int index = cycle.indexOf(beanInCycle);
            if (index == -1) {
                cycle.add(beanInCycle);
            }
            cycleStart = (cycleStart == -1 ? index : cycleStart);
        }
        candidate = candidate.getCause();
    }
    String message = buildMessage(cycle, cycleStart);
    return new FailureAnalysis(message, null, cause);
}
Also used : ArrayList(java.util.ArrayList) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) InjectionPoint(org.springframework.beans.factory.InjectionPoint)

Example 2 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) {
    FailureAnalysis analysis = this.analyzer.analyze(createFailure(configuration));
    assertThat(analysis).isNotNull();
    return analysis;
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis)

Example 3 with FailureAnalysis

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

the class BindFailureAnalyzerTests method bindExceptionWithFieldErrorsDueToValidationFailure.

@Test
public void bindExceptionWithFieldErrorsDueToValidationFailure() {
    FailureAnalysis analysis = performAnalysis(FieldValidationFailureConfiguration.class);
    assertThat(analysis.getDescription()).contains(failure("test.foo.foo", "null", "may not be null"));
    assertThat(analysis.getDescription()).contains(failure("test.foo.value", "0", "at least five"));
    assertThat(analysis.getDescription()).contains(failure("test.foo.nested.bar", "null", "may not be null"));
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.Test)

Example 4 with FailureAnalysis

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

the class ValidationFailureAnalyzerTests method analyzesMissingRequiredConfiguration.

@Test
void analyzesMissingRequiredConfiguration() {
    FailureAnalysis analysis = new ValidationFailureAnalyzer().analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
    assertThat(analysis).isNotNull();
    assertThat(analysis.getCause().getMessage()).contains("management.metrics.export.newrelic.apiKey was 'null'");
    assertThat(analysis.getDescription()).isEqualTo(String.format("Invalid Micrometer configuration detected:%n%n" + "  - management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API%n" + "  - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API"));
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 5 with FailureAnalysis

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

the class HikariDriverConfigurationFailureAnalyzerTests method failureAnalysisIsPerformed.

@Test
void failureAnalysisIsPerformed() {
    FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class);
    assertThat(failureAnalysis).isNotNull();
    assertThat(failureAnalysis.getDescription()).isEqualTo("Configuration of the Hikari connection pool failed: 'dataSourceClassName' is not supported.");
    assertThat(failureAnalysis.getAction()).contains("Spring Boot auto-configures only a driver");
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Aggregations

FailureAnalysis (org.springframework.boot.diagnostics.FailureAnalysis)86 Test (org.junit.jupiter.api.Test)69 MapPropertySource (org.springframework.core.env.MapPropertySource)6 Test (org.junit.Test)5 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 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 TestBeanConsumer (org.springframework.boot.diagnostics.analyzer.nounique.TestBeanConsumer)1