Search in sources :

Example 56 with FailureAnalysis

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

the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForNoMatchName.

@Test
void failureAnalysisForNoMatchName() {
    FailureAnalysis analysis = analyzeFailure(createFailure(StringNameHandler.class));
    assertThat(analysis.getDescription()).startsWith(String.format("Constructor in %s required a bean named '%s' that could not be found", StringNameHandler.class.getName(), "test-string"));
    assertThat(analysis.getAction()).startsWith(String.format("Consider defining a bean named '%s' in your configuration.", "test-string"));
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 57 with FailureAnalysis

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

the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForMultipleBeans.

@Test
void failureAnalysisForMultipleBeans() {
    FailureAnalysis analysis = analyzeFailure(new NoUniqueBeanDefinitionException(String.class, 2, "Test"));
    assertThat(analysis).isNull();
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) NoUniqueBeanDefinitionException(org.springframework.beans.factory.NoUniqueBeanDefinitionException) Test(org.junit.jupiter.api.Test)

Example 58 with FailureAnalysis

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

the class ConfigDataNotFoundFailureAnalyzer method analyze.

@Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataNotFoundException cause) {
    ConfigDataLocation location = getLocation(cause);
    Origin origin = Origin.from(location);
    String message = String.format("Config data %s does not exist", cause.getReferenceDescription());
    StringBuilder action = new StringBuilder("Check that the value ");
    if (location != null) {
        action.append(String.format("'%s' ", location));
    }
    if (origin != null) {
        action.append(String.format("at %s ", origin));
    }
    action.append("is correct");
    if (location != null && !location.isOptional()) {
        action.append(String.format(", or prefix it with '%s'", ConfigDataLocation.OPTIONAL_PREFIX));
    }
    return new FailureAnalysis(message, action.toString(), cause);
}
Also used : Origin(org.springframework.boot.origin.Origin) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis)

Example 59 with FailureAnalysis

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

the class ConfigDataNotFoundFailureAnalyzerTests method analyzeWhenConfigDataResourceWithLocationNotFoundException.

@Test
void analyzeWhenConfigDataResourceWithLocationNotFoundException() {
    ConfigDataLocation location = ConfigDataLocation.of("test");
    ConfigDataResource resource = new TestConfigDataResource("myresource");
    ConfigDataResourceNotFoundException exception = new ConfigDataResourceNotFoundException(resource).withLocation(location);
    FailureAnalysis result = this.analyzer.analyze(exception);
    assertThat(result.getDescription()).isEqualTo("Config data resource 'myresource' via location 'test' does not exist");
    assertThat(result.getAction()).isEqualTo("Check that the value 'test' is correct, or prefix it with 'optional:'");
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 60 with FailureAnalysis

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

the class ConfigDataNotFoundFailureAnalyzerTests method analyzeWhenConfigDataLocationWithOriginNotFoundException.

@Test
void analyzeWhenConfigDataLocationWithOriginNotFoundException() {
    ConfigDataLocation location = ConfigDataLocation.of("test").withOrigin(new TestOrigin("origin"));
    ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location);
    FailureAnalysis result = this.analyzer.analyze(exception);
    assertThat(result.getDescription()).isEqualTo("Config data location 'test' does not exist");
    assertThat(result.getAction()).isEqualTo("Check that the value 'test' at origin is correct, or prefix it with 'optional:'");
}
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