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.");
}
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')");
}
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"));
}
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());
}
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.");
}
Aggregations