diff --git a/java/core/src/test/java/sleeper/core/deploy/DeployInstanceConfigurationIT.java b/java/core/src/test/java/sleeper/core/deploy/DeployInstanceConfigurationIT.java index c7596f68a6..da9bcd5c37 100644 --- a/java/core/src/test/java/sleeper/core/deploy/DeployInstanceConfigurationIT.java +++ b/java/core/src/test/java/sleeper/core/deploy/DeployInstanceConfigurationIT.java @@ -38,7 +38,9 @@ public class DeployInstanceConfigurationIT { @TempDir - private Path tempDir; + private Path templatesDir; + @TempDir + private Path propertiesDir; @Nested @DisplayName("Load from template directory") @@ -46,11 +48,10 @@ class LoadFromTemplateDirectory { @Test void shouldLoadInstancePropertiesWithNoTables() throws Exception { // Given - createTemplatesInDirectory(tempDir); + writeTemplates(); // When - DeployInstanceConfiguration instanceConfiguration = DeployInstanceConfigurationFromTemplates.builder() - .templatesDir(tempDir).build().load(); + DeployInstanceConfiguration instanceConfiguration = fromTemplatesDir(); // Then InstanceProperties expectedInstanceProperties = new InstanceProperties(); @@ -70,15 +71,14 @@ class LoadFromInstanceProperties { @Test void shouldLoadTablePropertiesAndSchemaIfFoundNearInstanceProperties() throws Exception { // Given - Path templateDir = createTemplatesInDirectory(tempDir.resolve("templates")); - Files.writeString(tempDir.resolve("instance.properties"), "sleeper.id=test-instance"); - Files.writeString(tempDir.resolve("tags.properties"), "Project=TestProject"); - Files.writeString(tempDir.resolve("table.properties"), "sleeper.table.name=test-table"); - Files.writeString(tempDir.resolve("schema.json"), new SchemaSerDe().toJson(schemaWithKey("key"))); + Files.writeString(propertiesDir.resolve("instance.properties"), "sleeper.id=test-instance"); + Files.writeString(propertiesDir.resolve("tags.properties"), "Project=TestProject"); + Files.writeString(propertiesDir.resolve("table.properties"), "sleeper.table.name=test-table"); + Files.writeString(propertiesDir.resolve("schema.json"), new SchemaSerDe().toJson(schemaWithKey("key"))); // When DeployInstanceConfiguration instanceConfiguration = fromInstancePropertiesOrTemplatesDir( - tempDir.resolve("instance.properties"), templateDir); + propertiesDir.resolve("instance.properties")); // Then InstanceProperties expectedInstanceProperties = new InstanceProperties(); @@ -97,19 +97,15 @@ void shouldLoadTablePropertiesAndSchemaIfFoundNearInstanceProperties() throws Ex @Test void shouldLoadNoTablesIfNotFoundNearInstanceProperties() throws Exception { // Given - Path templateDir = createTemplatesInDirectory(tempDir.resolve("templates")); - Files.writeString(tempDir.resolve("instance.properties"), "sleeper.id=test-instance"); + Files.writeString(propertiesDir.resolve("instance.properties"), "sleeper.id=test-instance"); // When - DeployInstanceConfiguration instanceConfiguration = DeployInstanceConfigurationFromTemplates.builder() - .instancePropertiesPath(tempDir.resolve("instance.properties")) - .templatesDir(templateDir) - .build().load(); + DeployInstanceConfiguration instanceConfiguration = fromInstancePropertiesOrTemplatesDir( + propertiesDir.resolve("instance.properties")); // Then InstanceProperties expectedInstanceProperties = new InstanceProperties(); expectedInstanceProperties.set(ID, "test-instance"); - expectedInstanceProperties.setTags(Map.of("Project", "TemplateProject")); assertThat(instanceConfiguration) .isEqualTo(DeployInstanceConfiguration.builder() .instanceProperties(expectedInstanceProperties) @@ -118,17 +114,22 @@ void shouldLoadNoTablesIfNotFoundNearInstanceProperties() throws Exception { } } - private static Path createTemplatesInDirectory(Path templatesDir) throws IOException { + private void writeTemplates() throws IOException { Files.createDirectories(templatesDir); Files.writeString(templatesDir.resolve("instanceproperties.template"), "sleeper.id=template-instance"); Files.writeString(templatesDir.resolve("tags.template"), "Project=TemplateProject"); - return templatesDir; } - private DeployInstanceConfiguration fromInstancePropertiesOrTemplatesDir(Path instancePropertiesFile, Path templateDir) { + private DeployInstanceConfiguration fromInstancePropertiesOrTemplatesDir(Path instancePropertiesFile) { return DeployInstanceConfigurationFromTemplates.builder() .instancePropertiesPath(instancePropertiesFile) - .templatesDir(templateDir) + .templatesDir(templatesDir) + .build().load(); + } + + private DeployInstanceConfiguration fromTemplatesDir() { + return DeployInstanceConfigurationFromTemplates.builder() + .templatesDir(templatesDir) .build().load(); } }