Skip to content

Commit

Permalink
devonfw#1642 changed adaptTemplateSetsTest to use template sets from …
Browse files Browse the repository at this point in the history
…test ressources
  • Loading branch information
EduardKrieger committed Mar 21, 2023
1 parent 8811c01 commit fcd2be5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ objectdb
/cobigen/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar
cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar
cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set1-test-test.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0-TEST.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0-TEST-sources.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0-TEST.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0-TEST-sources.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0.jar
cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0-sources.jar
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
Expand All @@ -19,6 +18,9 @@
*/
public class AdaptTemplatesCommandIT extends AbstractCliTest {

/** Test resources root path */
private static String testFileRootPath = "src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded";

/**
* Checks if adapt-templates command successfully created adapted folder and its sub folders
*
Expand All @@ -27,29 +29,12 @@ public class AdaptTemplatesCommandIT extends AbstractCliTest {
@Test
public void adaptTemplateSetTest() throws Exception {

Path devTemplateSetPath = new File(
AdaptTemplatesCommandIT.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile().toPath().resolve("cobigen-templates")
.resolve("crud-java-server-app").resolve("target");
File jars = devTemplateSetPath.toFile();
List<String> filenames = new ArrayList<>(2);
for (File file : jars.listFiles()) {
if (file.getName().endsWith(".jar")) {
filenames.add(file.getName());
}
}
if (Files.exists(devTemplateSetPath)) {
Path downloadedTemplateSetsPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)
.resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
if (!Files.exists(downloadedTemplateSetsPath)) {
Files.createDirectories(downloadedTemplateSetsPath);
}
for (String jarFilename : filenames) {
Files.copy(devTemplateSetPath.resolve(jarFilename),
downloadedTemplateSetsPath.resolve(jarFilename.replace("-SNAPSHOT", "")));
}
Path downloadedTemplateSetsPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER)
.resolve(ConfigurationConstants.DOWNLOADED_FOLDER);
if (!Files.exists(downloadedTemplateSetsPath)) {
Files.createDirectories(downloadedTemplateSetsPath);
}

FileUtils.copyDirectory(new File(testFileRootPath), downloadedTemplateSetsPath.toFile());
String args[] = new String[2];
args[0] = "adapt-templates";
args[1] = "--all";
Expand All @@ -65,29 +50,45 @@ public void adaptTemplateSetTest() throws Exception {
assertThat(downloadedTemplateSetsFolderPath).exists();
assertThat(adaptedTemplateSetsFolderPath).exists();

Path templateSet = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-2021.12.007");
Path templateSetSimple = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-1.0.0");
Path templateSetComplex = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-complex-1.0.0");

// check if adapted template set exists
assertThat(templateSet).exists();
Path templateSetResourcesPath = templateSet.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
assertThat(templateSetSimple).exists();
assertThat(templateSetComplex).exists();

// check if templates folder exists
assertThat(templateSet.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER)).exists();
Path templateSetResourcesPath = templateSetSimple
.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);
Path templateSetResourcesPathComplex = templateSetComplex
.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER);

// check if template-set.xml exists
// check if templates folder exists
assertThat(templateSetSimple.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
.exists();
assertThat(
templateSet.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME))
templateSetComplex.resolve(templateSetResourcesPathComplex).resolve(ConfigurationConstants.TEMPLATES_FOLDER))
.exists();

// check if template-set.xml exists
assertThat(templateSetSimple.resolve(templateSetResourcesPath)
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex)
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();

// validate correct folder structure
assertThat(templateSet.resolve(templateSetResourcesPath)
assertThat(templateSetSimple.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER)
.resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();
assertThat(
templateSetComplex.resolve(templateSetResourcesPathComplex).resolve(ConfigurationConstants.TEMPLATES_FOLDER)
.resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists();

// check if template set utility resource folder exists
assertThat(templateSet.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
assertThat(templateSetSimple.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();
assertThat(templateSetComplex.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists();

// validate maven specific contents
assertThat(templateSet.resolve("pom.xml")).exists();
assertThat(templateSetSimple.resolve("pom.xml")).exists();
assertThat(templateSetComplex.resolve("pom.xml")).exists();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.devonfw.test</groupId>
<artifactId>crud-java-server-app-complex</artifactId>
<version>1.0.0-TEST</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.devonfw.test</groupId>
<artifactId>crud-java-server-app</artifactId>
<version>1.0.0-TEST</version>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down

0 comments on commit fcd2be5

Please sign in to comment.