Search in sources :

Example 81 with FailureAnalysis

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

the class BindValidationFailureAnalyzerTests method bindExceptionWithObjectErrorsDueToValidationFailure.

@Test
void bindExceptionWithObjectErrorsDueToValidationFailure() {
    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.jupiter.api.Test)

Example 82 with FailureAnalysis

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

the class InvalidConfigurationPropertyValueFailureAnalyzerTests method analysisWithKnownPropertyAndOtherCandidates.

@Test
void analysisWithKnownPropertyAndOtherCandidates() {
    MapPropertySource source = new MapPropertySource("test", Collections.singletonMap("test.property", "invalid"));
    MapPropertySource additional = new MapPropertySource("additional", Collections.singletonMap("test.property", "valid"));
    MapPropertySource another = new MapPropertySource("another", Collections.singletonMap("test.property", "test"));
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    this.environment.getPropertySources().addLast(additional);
    this.environment.getPropertySources().addLast(OriginCapablePropertySource.get(another));
    InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException("test.property", "invalid", "This is not valid.");
    FailureAnalysis analysis = performAnalysis(failure);
    assertCommonParts(failure, analysis);
    assertThat(analysis.getAction()).contains("Review the value of the property with the provided reason.");
    assertThat(analysis.getDescription()).contains("Additionally, this property is also set in the following property sources:").contains("In 'additional' with the value 'valid'").contains("In 'another' with the value 'test' (originating from 'TestOrigin test.property')");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) InvalidConfigurationPropertyValueException(org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 83 with FailureAnalysis

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

the class MutuallyExclusiveConfigurationPropertiesFailureAnalyzerTests method analyzeWhenAllConfiguredPropertiesAreInTheEnvironmentShouldReturnAnalysis.

@Test
void analyzeWhenAllConfiguredPropertiesAreInTheEnvironmentShouldReturnAnalysis() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("com.example.a", "alpha");
    properties.put("com.example.b", "bravo");
    MapPropertySource source = new MapPropertySource("test", properties);
    this.environment.getPropertySources().addFirst(OriginCapablePropertySource.get(source));
    MutuallyExclusiveConfigurationPropertiesException failure = new MutuallyExclusiveConfigurationPropertiesException(new HashSet<>(Arrays.asList("com.example.a", "com.example.b")), new HashSet<>(Arrays.asList("com.example.a", "com.example.b")));
    FailureAnalysis analysis = performAnalysis(failure);
    assertThat(analysis.getAction()).isEqualTo("Update your configuration so that only one of the mutually exclusive properties is configured.");
    assertThat(analysis.getDescription()).contains(String.format("The following configuration properties are mutually exclusive:%n%n\tcom.example.a%n\tcom.example.b%n")).contains(String.format("However, more than one of those properties has been configured at the same time:%n%n" + "\tcom.example.a (originating from 'TestOrigin test')%n" + "\tcom.example.b (originating from 'TestOrigin test')%n"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) MutuallyExclusiveConfigurationPropertiesException(org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException) Test(org.junit.jupiter.api.Test)

Example 84 with FailureAnalysis

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

the class BeanDefinitionOverrideFailureAnalyzerTests method analyzeBeanDefinitionOverrideException.

@Test
void analyzeBeanDefinitionOverrideException() {
    FailureAnalysis analysis = performAnalysis(BeanOverrideConfiguration.class);
    String description = analysis.getDescription();
    assertThat(description).contains("The bean 'testBean', defined in " + SecondConfiguration.class.getName() + ", could not be registered.");
    assertThat(description).contains(FirstConfiguration.class.getName());
}
Also used : FailureAnalysis(org.springframework.boot.diagnostics.FailureAnalysis) Test(org.junit.jupiter.api.Test)

Example 85 with FailureAnalysis

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

the class BeanDefinitionOverrideFailureAnalyzerTests method analyzeBeanDefinitionOverrideExceptionWithDefinitionsWithNoResourceDescription.

@Test
void analyzeBeanDefinitionOverrideExceptionWithDefinitionsWithNoResourceDescription() {
    FailureAnalysis analysis = performAnalysis((context) -> {
        context.registerBean("testBean", String.class, (Supplier<String>) String::new);
        context.registerBean("testBean", String.class, (Supplier<String>) String::new);
    });
    String description = analysis.getDescription();
    assertThat(description).isEqualTo("The bean 'testBean' could not be registered. A bean with that name has already" + " been defined and overriding is disabled.");
}
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