Add a FailureAnalyzer for ConfigDataNotFound
Add a `FailureAnalyzer` to deal with `ConfigDataNotFoundException`. See gh-23633
This commit is contained in:
parent
1cf9fc107e
commit
be7d697121
|
|
@ -0,0 +1,21 @@
|
|||
package org.springframework.boot.context.config;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
/**
|
||||
*
|
||||
* An implementation of {@link AbstractFailureAnalyzer} to analyze failures caused by
|
||||
* {@link ConfigDataLocationNotFoundException}.
|
||||
*
|
||||
* @author Michal Mlak
|
||||
*/
|
||||
public class ConfigDataLocationNotFoundExceptionFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<ConfigDataLocationNotFoundException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, ConfigDataLocationNotFoundException cause) {
|
||||
return new FailureAnalysis(cause.getMessage(), null, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -74,7 +74,8 @@ org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer
|
|||
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyNameFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.InvalidConfigurationPropertyValueFailureAnalyzer,\
|
||||
org.springframework.boot.diagnostics.analyzer.PatternParseFailureAnalyzer,\
|
||||
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer
|
||||
org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer,\
|
||||
org.springframework.boot.context.config.ConfigDataLocationNotFoundExceptionFailureAnalyzer
|
||||
|
||||
# Failure Analysis Reporters
|
||||
org.springframework.boot.diagnostics.FailureAnalysisReporter=\
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package org.springframework.boot.context.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
*
|
||||
* Tests for {@link ConfigDataLocationNotFoundExceptionFailureAnalyzer}
|
||||
*
|
||||
* @author Michal Mlak
|
||||
*/
|
||||
class ConfigDataLocationNotFoundExceptionFailureAnalyzerTests {
|
||||
|
||||
private final ConfigDataLocationNotFoundExceptionFailureAnalyzer analyzer = new ConfigDataLocationNotFoundExceptionFailureAnalyzer();
|
||||
|
||||
@Test
|
||||
void failureAnalysisForConfigDataLocationNotFound() {
|
||||
ConfigDataLocation location = mock(ConfigDataLocation.class);
|
||||
ConfigDataLocationNotFoundException exception = new ConfigDataLocationNotFoundException(location);
|
||||
|
||||
FailureAnalysis result = analyzer.analyze(exception);
|
||||
|
||||
assertThat(result.getDescription()).isEqualTo("Config data location '" + location + "' does not exist");
|
||||
assertThat(result.getAction()).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue