ConfigDataLocationRuntimeHintsTests Class — spring-boot Architecture
Architecture documentation for the ConfigDataLocationRuntimeHintsTests class in ConfigDataLocationRuntimeHintsTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationRuntimeHintsTests.java lines 43–148
class ConfigDataLocationRuntimeHintsTests {
@Test
@WithResource(name = "application.properties", content = "")
@WithResource(name = "config/application.properties", content = "")
void registerWithDefaultSettings() {
RuntimeHints hints = new RuntimeHints();
new TestConfigDataLocationRuntimeHints().registerHints(hints, Thread.currentThread().getContextClassLoader());
assertThat(hints.resources().resourcePatternHints()).singleElement()
.satisfies(includes("application*.properties", "application*.xml", "application*.yaml", "application*.yml",
"config/application*.properties", "config/application*.xml", "config/application*.yaml",
"config/application*.yml"));
}
@Test
@WithResource(name = "test.properties")
@WithResource(name = "config/test.properties")
void registerWithCustomName() {
RuntimeHints hints = new RuntimeHints();
new TestConfigDataLocationRuntimeHints() {
@Override
protected List<String> getFileNames(@Nullable ClassLoader classLoader) {
return List.of("test");
}
}.registerHints(hints, Thread.currentThread().getContextClassLoader());
assertThat(hints.resources().resourcePatternHints()).singleElement()
.satisfies(includes("test*.properties", "test*.xml", "test*.yaml", "test*.yml", "config/test*.properties",
"config/test*.xml", "config/test*.yaml", "config/test*.yml"));
}
@Test
@WithResource(name = "application.properties")
@WithResource(name = "config/application.properties")
void registerWithCustomLocation() {
RuntimeHints hints = new RuntimeHints();
new TestConfigDataLocationRuntimeHints() {
@Override
protected List<String> getLocations(@Nullable ClassLoader classLoader) {
return List.of("config/");
}
}.registerHints(hints, Thread.currentThread().getContextClassLoader());
assertThat(hints.resources().resourcePatternHints()).singleElement()
.satisfies(includes("config/application*.properties", "config/application*.xml", "config/application*.yaml",
"config/application*.yml"));
}
@Test
@WithResource(name = "application.conf")
@WithResource(name = "config/application.conf")
void registerWithCustomExtension() {
RuntimeHints hints = new RuntimeHints();
new ConfigDataLocationRuntimeHints() {
@Override
protected List<String> getExtensions(@Nullable ClassLoader classLoader) {
return List.of(".conf");
}
}.registerHints(hints, Thread.currentThread().getContextClassLoader());
assertThat(hints.resources().resourcePatternHints()).singleElement()
.satisfies(includes("application*.conf", "config/application*.conf"));
}
@Test
void registerWithUnknownLocationDoesNotAddHint() {
RuntimeHints hints = new RuntimeHints();
new ConfigDataLocationRuntimeHints() {
@Override
protected List<String> getLocations(@Nullable ClassLoader classLoader) {
return List.of(UUID.randomUUID().toString());
}
}.registerHints(hints, Thread.currentThread().getContextClassLoader());
assertThat(hints.resources().resourcePatternHints()).isEmpty();
}
private Consumer<ResourcePatternHints> includes(String... patterns) {
return (hint) -> assertThat(hint.getIncludes().stream().map(ResourcePatternHint::getPattern))
.contains(patterns);
}
static class TestConfigDataLocationRuntimeHints extends ConfigDataLocationRuntimeHints {
private final MockSpringFactoriesLoader springFactoriesLoader;
TestConfigDataLocationRuntimeHints(MockSpringFactoriesLoader springFactoriesLoader) {
this.springFactoriesLoader = springFactoriesLoader;
}
TestConfigDataLocationRuntimeHints() {
this(springFactoriesLoader());
}
private static MockSpringFactoriesLoader springFactoriesLoader() {
MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
springFactoriesLoader.add(PropertySourceLoader.class, PropertiesPropertySourceLoader.class,
YamlPropertySourceLoader.class);
return springFactoriesLoader;
}
@Override
protected SpringFactoriesLoader getSpringFactoriesLoader(@Nullable ClassLoader classLoader) {
return this.springFactoriesLoader;
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free