Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template set deployables tests #6

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved

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(Files.isDirectory(extractedJar1));
assertThat(Files.isDirectory(extractedJar2));
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Test of extract templates with old CobiGen_Templates project existing
*
* @throws IOException if an Exception occurs
*/
@Test
public void extractTemplatesWithOldConfiguration() throws IOException {
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved

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(Files.isDirectory(cobigenTemplatesProject));
jan-vcapgemini marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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,18 +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 +150,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