Skip to content

Commit

Permalink
Merge pull request #6 from jan-vcapgemini/template_set_deployables_tests
Browse files Browse the repository at this point in the history
Template set deployables tests
  • Loading branch information
jan-vcapgemini authored Apr 8, 2022
2 parents 8c33a78 + 604dce5 commit f6304d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
5 changes: 2 additions & 3 deletions cobigen-eclipse/cobigen-eclipse-test/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/">
Expand All @@ -17,7 +15,6 @@
<classpathentry exported="true" kind="lib" path="lib/error_prone_annotations.jar"/>
<classpathentry exported="true" kind="lib" path="lib/failureaccess.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest-core.jar"/>
<classpathentry exported="true" kind="lib" path="lib/j2objc-annotations.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jcl-over-slf4j.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jsr305.jar"/>
Expand All @@ -32,5 +29,7 @@
<classpathentry exported="true" kind="lib" path="lib/system-lambda.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xmlunit.jar"/>
<classpathentry exported="true" kind="lib" path="lib/zt-exec.jar"/>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="output" path="eclipse-target/classes"/>
</classpath>
1 change: 0 additions & 1 deletion cobigen-eclipse/cobigen-eclipse-test/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ bin.includes = .,\
lib/error_prone_annotations.jar,\
lib/failureaccess.jar,\
lib/guava.jar,\
lib/hamcrest-core.jar,\
lib/j2objc-annotations.jar,\
lib/jcl-over-slf4j.jar,\
lib/jsr305.jar,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ public void callClassLoadingTest() throws Exception {
// Verification
File expectedResult = new File(testFileRootPath, "expected/Test.java");
File generatedFile = new File(generationRootFolder, "com/devonfw/Test.java");
report.isSuccessful();
assertThat(report).isSuccessful();
assertThat(generatedFile).exists();
assertThat(generatedFile).isFile().hasSameContentAs(expectedResult);

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TemplateProcessingTest extends AbstractApiTest {
/**
* temporary project to store CobiGen home
*/
File cobiGenHome;
Path cobiGenHome;

/**
* Creates a temporary CobiGen home directory for each test and create static mock for CobiGenPaths object
Expand All @@ -56,10 +56,10 @@ public class TemplateProcessingTest extends AbstractApiTest {
@Before
public void prepare() throws IOException {

this.cobiGenHome = this.tempFolder.newFolder("playground", "templatesHome");
this.cobiGenHome = this.tempFolder.newFolder("playground", "templatesHome").toPath();

this.cobigenPaths = Mockito.mockStatic(CobiGenPaths.class, Mockito.CALLS_REAL_METHODS);
this.cobigenPaths.when(() -> CobiGenPaths.getCobiGenHomePath()).thenReturn(this.cobiGenHome.toPath());
this.cobigenPaths.when(() -> CobiGenPaths.getCobiGenHomePath()).thenReturn(this.cobiGenHome);

}

Expand All @@ -73,35 +73,36 @@ public void cleanup() {
}

/**
* Tests if template sets can be extracted properly
*
* @throws IOException if an Exception occurs
*/
@Test
public void extractTemplateSetsTest() throws IOException {
private void extractTemplateSetsTest() throws IOException {

FileUtils.copyDirectory(new File(testFileRootPath + "templates"),
this.cobiGenHome.toPath().resolve("template-sets/downloaded").toFile());
this.cobiGenHome.resolve("template-sets/downloaded").toFile());
CobiGenFactory.extractTemplates();
Path adaptedFolder = this.cobiGenHome.toPath().resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)
Path adaptedFolder = this.cobiGenHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)
.resolve(ConfigurationConstants.ADAPTED_FOLDER);
Path extractedJar1 = adaptedFolder.resolve("template-test1-0.0.1");
Path extractedJar2 = adaptedFolder.resolve("template-test2-0.0.1");
assertThat(extractedJar1.toFile()).exists().isDirectory();
assertThat(extractedJar2.toFile()).exists().isDirectory();
assertThat(extractedJar1).exists().isDirectory();
assertThat(extractedJar2).exists().isDirectory();
}

/**
* Test of extract templates with old CobiGen_Templates project existing
*
* @throws IOException if an Exception occurs
*/
@Test
public void extractTemplatesWithOldConfiguration() throws IOException {
private void extractTemplatesWithOldConfiguration() throws IOException {

Path cobigenTemplatesParent = this.cobiGenHome.toPath()
.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH);
Path cobigenTemplatesParent = this.cobiGenHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH);
Files.createDirectories(cobigenTemplatesParent);
Path cobigenTemplatesProject = cobigenTemplatesParent.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
Files.createDirectories(cobigenTemplatesProject);
CobiGenFactory.extractTemplates();
assertThat(cobigenTemplatesProject.toFile()).exists().isDirectory();
assertThat(cobigenTemplatesProject).exists().isDirectory();
}

/**
Expand All @@ -112,7 +113,7 @@ public void extractTemplatesWithOldConfiguration() throws IOException {
@Test
public void testExtractTemplatesWithOldConfiguration() throws Exception {

withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toString())
.execute(() -> extractTemplatesWithOldConfiguration());
}

Expand All @@ -124,19 +125,19 @@ public void testExtractTemplatesWithOldConfiguration() throws Exception {
@Test
public void testExtractTemplateSets() throws Exception {

withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
.execute(() -> extractTemplateSetsTest());
withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toString()).execute(() -> extractTemplateSetsTest());
}

/**
* Test of find template set downloaded folder to ensure backwards compatibility
*
* @throws IOException if an Exception occurs
*/
private void findTemplateSetJarsWithBackwardsCompatibilityTest() throws IOException {

FileUtils.createParentDirectories(new File(testFileRootPath + "template-sets"));
URI templatesLocationURI = ConfigurationFinder.findTemplatesLocation();
assertThat(templatesLocationURI.compareTo(this.cobiGenHome.toPath().resolve("template-sets").toUri()));

assertThat(templatesLocationURI.compareTo(this.cobiGenHome.resolve("template-sets").toUri()));
}

/**
Expand All @@ -148,7 +149,7 @@ private void findTemplateSetJarsWithBackwardsCompatibilityTest() throws IOExcept
@Test
public void testfindTemplateSetDownloadedWithBackwardsCompatibility() throws Exception {

withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toPath().toString())
withEnvironmentVariable("COBIGEN_HOME", this.cobiGenHome.toString())
.execute(() -> findTemplateSetJarsWithBackwardsCompatibilityTest());
}

Expand Down

0 comments on commit f6304d2

Please sign in to comment.