Skip to content

Commit

Permalink
devonfw#1696: adjusted TemplateSetReaderTest to new API
Browse files Browse the repository at this point in the history
fixed valid template set file (made sure that all 3 templates can be read)
  • Loading branch information
jan-vcapgemini committed Aug 10, 2023
1 parent c8e2ab7 commit e71c207
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.");

}

Expand All @@ -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.");
Expand Down Expand Up @@ -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);

}

Expand All @@ -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);

}
Expand All @@ -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);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<tns:templateSetConfiguration version="6.0" xmlns:tns="http://capgemini.com/devonfw/cobigen/TemplateSetConfiguration" xmlns:cc="http://capgemini.com/devonfw/cobigen/ContextConfiguration" xmlns:tc="http://capgemini.com/devonfw/cobigen/TemplatesConfiguration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://capgemini.com/devonfw/cobigen/TemplateSetConfiguration templateSetConfiguration.xsd ">

<cc:contextConfiguration version="6.0">
<cc:trigger id="valid" type="java">
<cc:trigger id="valid1" type="java">
<cc:matcher type="fqn" value="*"></cc:matcher>
</cc:trigger>
<cc:tags>
Expand Down

0 comments on commit e71c207

Please sign in to comment.