Archived
0

refactoring: реорганизация загрузки конфигураций

This commit is contained in:
2021-06-13 14:37:45 +03:00
parent e76f7ff375
commit 222f2dba61
10 changed files with 187 additions and 10 deletions

View File

@@ -12,10 +12,15 @@ import static org.junit.jupiter.api.Assertions.*;
class ConfigModuleTest {
private static final String emptyConfig = "./config-empty.conf";
/*
Проверяем, что загруженный объект конфига является singleton
*/
@Test
void singleton() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
Config config1 = component.getConfig();
Config config2 = component.getConfig();
@@ -23,10 +28,13 @@ class ConfigModuleTest {
assertSame(config1, config2);
}
/*
Корректная загрузка конфига
*/
@Test
void loadConfig() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
Config config = component.getConfig();
assertEquals("value1", config.getString("key1"));
@@ -36,10 +44,13 @@ class ConfigModuleTest {
assertEquals("value5", config.getString("key5"));
}
/*
Проверка include
*/
@Test
void includeTest() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-2.conf"))).build();
.configModule(new ConfigModule(emptyConfig, pathResource("/config-2.conf"))).build();
Config config = component.getConfig();
assertEquals("value1", config.getString("key1"));
@@ -49,6 +60,31 @@ class ConfigModuleTest {
assertEquals("value5", config.getString("key5"));
}
/*
Работа с многострочностью
*/
@Test
void multilineTest() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
Config config = component.getConfig();
assertEquals("line1\nline2", config.getString("key6"));
}
/*
Проверяем работу merge config
*/
@Test
void mergeConfigTest() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule("./config-1.conf", pathResource("/config-3.conf"))).build();
Config config = component.getConfig();
assertEquals("value1_merged", config.getString("key1"));
assertEquals("value2", config.getString("key2.subkey1"));
}
@SneakyThrows
private static Path pathResource(String resource) {
URL url = ConfigModuleTest.class.getResource(resource);