UnboundConfigurationPropertyFailureAnalyzerTests Class — spring-boot Architecture
Architecture documentation for the UnboundConfigurationPropertyFailureAnalyzerTests class in UnboundConfigurationPropertyFailureAnalyzerTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/UnboundConfigurationPropertyFailureAnalyzerTests.java lines 45–124
class UnboundConfigurationPropertyFailureAnalyzerTests {
@BeforeEach
void setup() {
LocaleContextHolder.setLocale(Locale.US);
}
@AfterEach
void cleanup() {
LocaleContextHolder.resetLocaleContext();
}
@Test
void bindExceptionDueToUnboundElements() {
FailureAnalysis analysis = performAnalysis(UnboundElementsFailureConfiguration.class,
"test.foo.listValue[0]=hello", "test.foo.listValue[2]=world");
assertThat(analysis.getDescription()).contains(
failure("test.foo.listvalue[2]", "world", "\"test.foo.listValue[2]\" from property source \"test\"",
"The elements [test.foo.listvalue[2]] were left unbound."));
}
private static String failure(String property, String value, String origin, String reason) {
return String.format("Property: %s%n Value: \"%s\"%n Origin: %s%n Reason: %s", property, value, origin,
reason);
}
private FailureAnalysis performAnalysis(Class<?> configuration, String... environment) {
BeanCreationException failure = createFailure(configuration, environment);
FailureAnalysis analyze = new UnboundConfigurationPropertyFailureAnalyzer().analyze(failure);
assertThat(analyze).isNotNull();
return analyze;
}
private BeanCreationException createFailure(Class<?> configuration, String... environment) {
try {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
addEnvironment(context, environment);
context.register(configuration);
context.refresh();
context.close();
throw new AssertionError("Should not be reached");
}
catch (BeanCreationException ex) {
return ex;
}
}
private void addEnvironment(AnnotationConfigApplicationContext context, String[] environment) {
MutablePropertySources sources = context.getEnvironment().getPropertySources();
Map<String, Object> map = new HashMap<>();
for (String pair : environment) {
int index = pair.indexOf('=');
String key = (index > 0) ? pair.substring(0, index) : pair;
String value = (index > 0) ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());
}
sources.addFirst(new MapPropertySource("test", map));
}
@EnableConfigurationProperties(UnboundElementsFailureProperties.class)
static class UnboundElementsFailureConfiguration {
}
@ConfigurationProperties("test.foo")
static class UnboundElementsFailureProperties {
private @Nullable List<String> listValue;
@Nullable List<String> getListValue() {
return this.listValue;
}
void setListValue(@Nullable List<String> listValue) {
this.listValue = listValue;
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free