Skip to content

Commit

Permalink
Create directory for resources in TestPlatformConfigProvider (#3136)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Rol <nicolas.rol@rte-france.com>
  • Loading branch information
rolnico authored Sep 9, 2024
1 parent e0287a9 commit 37c8014
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public PlatformConfig getPlatformConfig() {
// The resources have relative paths (no leading slash) with full package path.
Path dest = cfgDir.resolve(resource);
LOGGER.info("Copying classpath resource: {} -> {}", resource, dest);
Files.createDirectories(dest.getParent());
Files.copy(TestPlatformConfigProvider.class.getResourceAsStream(resource), dest);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ void test() throws IOException {
assertEquals("/work/" + TestPlatformConfigProvider.CONFIG_DIR,
platformConfig.getConfigDir().map(Path::toString).orElse(null));

Path testPath = platformConfig.getConfigDir().map(p -> p.resolve("other.txt")).orElse(null);
checkFileContent(platformConfig, "other.txt", "conf");
checkFileContent(platformConfig, "subfolder/subfolder_file.txt", "subfile content");
assertEquals("baz", platformConfig.getOptionalModuleConfig("foo").flatMap(c -> c.getOptionalStringProperty("bar")).orElse(""));
}

private void checkFileContent(PlatformConfig platformConfig, String file, String content) throws IOException {
Path testPath = platformConfig.getConfigDir().map(p -> p.resolve(file)).orElse(null);
assertNotNull(testPath);
String testContent = Files.readAllLines(testPath, StandardCharsets.UTF_8).get(0);
assertEquals("conf", testContent);
assertEquals("baz", platformConfig.getOptionalModuleConfig("foo").flatMap(c -> c.getOptionalStringProperty("bar")).orElse(""));
assertEquals(content, testContent);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config.yml
other.txt
base-voltages.yml
subfolder/subfolder_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subfile content

0 comments on commit 37c8014

Please sign in to comment.