From e71c207e1aee14bf5091ed3db1ec0398a2135b3b Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Thu, 10 Aug 2023 12:43:30 +0200 Subject: [PATCH] #1696: adjusted TemplateSetReaderTest to new API fixed valid template set file (made sure that all 3 templates can be read) --- .../config/reader/TemplateSetReaderTest.java | 28 ++++++++----------- .../src/main/resources/template-set.xml | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/config/reader/TemplateSetReaderTest.java b/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/config/reader/TemplateSetReaderTest.java index c88da8e1b..c8ad06f62 100644 --- a/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/config/reader/TemplateSetReaderTest.java +++ b/cobigen/cobigen-core/src/test/java/com/devonfw/cobigen/unittest/config/reader/TemplateSetReaderTest.java @@ -9,9 +9,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import com.devonfw.cobigen.impl.config.TemplatesConfiguration; -import com.devonfw.cobigen.impl.config.entity.Trigger; -import com.devonfw.cobigen.impl.config.reader.TemplateSetsConfigReader; import org.apache.commons.io.FileUtils; import org.junit.Ignore; import org.junit.Rule; @@ -23,6 +20,7 @@ import com.devonfw.cobigen.api.util.CobiGenPaths; import com.devonfw.cobigen.impl.config.ContextConfiguration; import com.devonfw.cobigen.impl.config.reader.TemplateSetReader; +import com.devonfw.cobigen.impl.config.reader.TemplateSetsConfigReader; import com.devonfw.cobigen.unittest.config.common.AbstractUnitTest; import junit.framework.TestCase; @@ -57,13 +55,14 @@ public class TemplateSetReaderTest extends AbstractUnitTest { public void testErrorOnInvalidConfiguration() throws InvalidConfigurationException { // when + Path faultyPath = TEST_FILE_ROOT_PATH.resolve("faulty").toAbsolutePath().resolve("template-sets"); assertThatThrownBy(() -> { - new ContextConfiguration(null, null, TEST_FILE_ROOT_PATH.resolve("faulty")); + TemplateSetsConfigReader reader = new TemplateSetsConfigReader(faultyPath); + reader.readContextConfiguration(); }).isInstanceOf(InvalidConfigurationException.class) - .hasMessage(TEST_FILE_ROOT_PATH.resolve("faulty").toAbsolutePath() + ":\n" - + "Could not find any template-set configuration file in the given folder."); + .hasMessage(faultyPath + ":\n" + "Could not find any template-set configuration file in the given folder."); } @@ -75,12 +74,12 @@ public void testErrorOnInvalidConfiguration() throws InvalidConfigurationExcepti * */ @Test - @Ignore // TODO: check if this exception is still needed public void testInvalidTemplateSets() throws InvalidConfigurationException { assertThatThrownBy(() -> { - new ContextConfiguration(null, null, INVALID_CONFIGURATION_PATH); + TemplateSetsConfigReader reader = new TemplateSetsConfigReader(INVALID_CONFIGURATION_PATH); + reader.readContextConfiguration(); }).isInstanceOf(InvalidConfigurationException.class).hasMessage(INVALID_CONFIGURATION_PATH.toAbsolutePath() + ":\n" + "Could not find any template-set configuration file in the given folder."); @@ -122,9 +121,8 @@ public void testTemplateSetsDownloaded() throws Exception { FileUtils.copyDirectory(templateSetPath.toFile(), folder); CobiGenPaths.setCobiGenHomeTestPath(folder.toPath()); - ContextConfiguration templateSetConfiguration = new ContextConfiguration(null, null, - folder.toPath().resolve("template-sets")); - assertThat(templateSetConfiguration.getTriggers().size()).isEqualTo(1); + TemplateSetsConfigReader reader = new TemplateSetsConfigReader(folder.toPath().resolve("template-sets")); + assertThat(reader.readContextConfiguration().getTriggers().size()).isEqualTo(1); } @@ -142,9 +140,8 @@ public void testTemplateSetsAdaptedAndDownloaded() throws Exception { Path templateSetPath = TEST_FILE_ROOT_PATH.resolve("valid_template_sets/"); FileUtils.copyDirectory(templateSetPath.toFile(), folder); CobiGenPaths.setCobiGenHomeTestPath(folder.toPath()); - - TemplateSetsConfigReader reader = new TemplateSetsConfigReader(folder.toPath().resolve("template-sets")); + TemplateSetsConfigReader reader = new TemplateSetsConfigReader(folder.toPath().resolve("template-sets")); assertThat(reader.readContextConfiguration().getTriggers().size()).isEqualTo(3); } @@ -166,10 +163,9 @@ public void testGetTemplatesWithInvalidAdaptedFolder() throws Exception { Files.createDirectory(folder.toPath().resolve("template-sets").resolve("adapted").resolve(".settings")); CobiGenPaths.setCobiGenHomeTestPath(folder.toPath()); - ContextConfiguration templateSetConfiguration = new ContextConfiguration(null, null, - folder.toPath().resolve("template-sets")); - assertThat(templateSetConfiguration.getTriggers().size()).isEqualTo(3); + TemplateSetsConfigReader reader = new TemplateSetsConfigReader(folder.toPath().resolve("template-sets")); + assertThat(reader.readContextConfiguration().getTriggers().size()).isEqualTo(3); } diff --git a/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets/template-sets/adapted/template-set/src/main/resources/template-set.xml b/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets/template-sets/adapted/template-set/src/main/resources/template-set.xml index f29b28a87..deaf0cea5 100644 --- a/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets/template-sets/adapted/template-set/src/main/resources/template-set.xml +++ b/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets/template-sets/adapted/template-set/src/main/resources/template-set.xml @@ -2,7 +2,7 @@ - +