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

#1509 Adapt template sets in Eclipse #1631

Closed
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions cobigen-eclipse/cobigen-eclipse-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<properties>
<tycho.testArgLine.enriched>${surefireArgLineIntegration} -Xms512m -Xmx2048m -XX:+DisableExplicitGC</tycho.testArgLine.enriched>
<enforcer.skip>true</enforcer.skip>
<maven.test.AdaptTemplatesTest1>src\main\resources\AdaptTemplatesTest\template-sets\adapted\crud-java-server-app</maven.test.AdaptTemplatesTest1>
<maven.test.AdaptTemplatesTest2>src\main\resources\AdaptTemplatesTest\template-sets\adapted\crud-java-server-app-complex</maven.test.AdaptTemplatesTest2>

</properties>

<dependencies>
Expand Down Expand Up @@ -58,6 +61,53 @@
</execution>
</executions>
</plugin>

<!-- Building a Maven project that is used on the tests -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>Install test adaptTemplatesTests1</id>
<phase>test-compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${maven.test.AdaptTemplatesTest1}</workingDirectory>
<arguments>
<argument>install</argument>
<!-- https://stackoverflow.com/a/66801171 -->
<argument>-Djansi.force=true</argument>
<argument>-Djansi.passthrough=true</argument>
<argument>-B</argument>
<argument>-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>Install test adaptTemplatesTests2</id>
<phase>test-compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${maven.test.AdaptTemplatesTest2}</workingDirectory>
<arguments>
<argument>install</argument>
<!-- https://stackoverflow.com/a/66801171 -->
<argument>-Djansi.force=true</argument>
<argument>-Djansi.passthrough=true</argument>
<argument>-B</argument>
<argument>-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
Expand All @@ -16,6 +19,7 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -44,6 +48,9 @@ public class AdaptTemplatesTest extends SystemTest {
/** Line separator, e.g. for windows '\r\n' */
public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator");

/* Root path for templateSets jar */
private static final String testResource = "src/main/resources/AdaptTemplatesTest/template-sets/downloaded";

/**
* Setup workbench appropriately for tests
*
Expand All @@ -60,7 +67,92 @@ public static void setupClass() throws Exception {
*
* @throws Exception test fails
*/
public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
public void testBasicOpenAPIGenerationWithAdaptTemplateSets() throws Exception {

// copy sample project to external location and import it into the workspace
String testProjName = "ExtTestProj";
IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName);
FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"),
project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile());
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
this.tmpMavenProjectRule.updateProject();

/**
* TODO Before the templates are made available online, the update (download) command cannot be tested.
cedricarnauld123 marked this conversation as resolved.
Show resolved Hide resolved
*/
// EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this commented out code for?

EclipseCobiGenUtils.runAndCaptureAdaptTemplatesSets(bot);
EclipseUtils.openErrorsTreeInProblemsView(bot);
// expand the new file in the package explorer
SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml");
javaClassItem.select();

// execute CobiGen
EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
bot.waitUntil(new AllJobsAreFinished(), 10000);
// increase timeout as the openAPI parser is slow on initialization
EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);

bot.waitUntil(new AllJobsAreFinished(), 10000);
IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(testProjName);
IFile generationResult = proj.getFile(
"src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java");

assertThat(generationResult.exists()).isTrue();
}

/**
* Test for external projects (not in workspace) taken as input for generation
*
* @throws Exception test fails
*/
public void testAdaptTemplatesAndImportIntoEclipse() throws Exception {

// copy sample project to external location and import it into the workspace
String testProjName = "ExtTestProj";
IJavaProject project = this.tmpMavenProjectRule.createProject(testProjName);
FileUtils.copyFile(new File(resourcesRootPath + "input/adapt-templates.yml"),
project.getUnderlyingResource().getLocation().append("adapt-templates.yml").toFile());
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
this.tmpMavenProjectRule.updateProject();

EclipseCobiGenUtils.runAndCaptureAdaptTemplatesSets(bot);

// EclipseUtils.updateMavenProject(bot, ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);

// expand the new file in the package explorer
SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml");
javaClassItem.select();

// execute CobiGen
EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
bot.waitUntil(new AllJobsAreFinished(), 10000);
// increase timeout as the openAPI parser is slow on initialization
EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);
bot.waitUntil(new AllJobsAreFinished(), 10000);

// EclipseUtils.openErrorsTreeInProblemsView(bot);

IProject generatorProjOfTempltesSets = ResourcesPlugin.getWorkspace().getRoot()
.getProject(ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);
bot.waitUntil(new AllJobsAreFinished(), 10000);

Path adaptedFolder = Paths.get(generatorProjOfTempltesSets.getLocationURI())
.resolve(ResourceConstants.TEMPLATE_SETS_ADAPTED);

assertThat(generatorProjOfTempltesSets.exists()).isTrue();
assertThat(Files.exists(adaptedFolder)).isTrue();

}

/**
* Test for external projects (not in workspace) taken as input for generation
*
* @throws Exception test fails
*/
public void testBasicOpenAPIGenerationWithAdaptMonolithicTemplates() throws Exception {

// copy sample project to external location and import it into the workspace
String testProjName = "ExtTestProj";
Expand All @@ -72,15 +164,9 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {

// retrieve CobiGen home directory (overwritten through environment variables)
File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile();

// create templates directory as this should be present in this scenario
this.tempFolder.newFolder("playground", "project", "templates");

// download latest monolithic templates to simulate existing template jars
TemplatesJarUtil.downloadLatestDevon4jTemplates(true, templatesDirectory);
TemplatesJarUtil.downloadLatestDevon4jTemplates(false, templatesDirectory);

// adapt template jars into CobiGen_Templates project
EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot);
EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME);

Expand All @@ -92,8 +178,7 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
javaClassItem.select();

// execute CobiGen
EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "CRUD devon4j Server>CRUD REST services");

EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
bot.waitUntil(new AllJobsAreFinished(), 10000);
// increase timeout as the openAPI parser is slow on initialization
EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);
Expand All @@ -104,19 +189,57 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
"src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java");

assertThat(generationResult.exists()).isTrue();
}

/*
*
* Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
*
*/
@Test
public void testAdaptMonolithicTemplatesAndGenerate() throws Exception {

File tmpProject = this.tempFolder.newFolder("playground", "project");
withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
.execute(() -> testBasicOpenAPIGenerationWithAdaptMonolithicTemplates());
}

/**
* Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
* TODO Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom template-sets after adapt the jar files
*
* @throws Exception test fails
*/
@Test
public void testAdaptTemplatesAndGenerate() throws Exception {
@Ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should always be an explanation why a particular test is being ignored. It is probably because of the TODO?

public void testAdaptTemplateSetsAndGenerate() throws Exception {

Path devTemplatesPath = new File(
AdaptTemplatesTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
.getParentFile().toPath().resolve("cobigen-templates").resolve("crud-openapi-java-server-app")
.resolve("target").resolve("crud-openapi-java-server-app-2021.12.007-SNAPSHOT.jar");

File tmpProject = this.tempFolder.newFolder("playground", "project");
File downloaded = this.tempFolder.newFolder("playground", "project", "template-sets", "downloaded");
FileUtils.copyFileToDirectory(devTemplatesPath.toFile(), downloaded);
withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
.execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates());
.execute(() -> testBasicOpenAPIGenerationWithAdaptTemplateSets());
}

/**
* Test adaption of template-sets/downloaded/.jar files and importing the project into Eclipse
*
* @throws Exception
*/
@Test
public void testAdaptTemplateSetsAndImport() throws Exception {

File tmpProject = this.tempFolder.newFolder("playground", "project");
File downloaded = this.tempFolder.newFolder("playground", "project", "template-sets", "downloaded");

FileUtils.copyDirectory(new File(testResource), downloaded);

withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
.execute(() -> testAdaptTemplatesAndImportIntoEclipse());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -359,7 +360,8 @@ private static void captureAdvancedHealthCheck(SWTWorkbenchBot bot) {
*/
public static void runAndCaptureUpdateTemplates(SWTWorkbenchBot bot) throws Exception {

ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time

SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
Expand Down Expand Up @@ -400,6 +402,26 @@ public static void runAndCaptureAdaptTemplates(SWTWorkbenchBot bot) throws Excep
informationDialog.bot().button("Ok").click();
}

/**
* Checks the CobiGen Adapt TemplateSets and takes screenshots of it.
*
* @param bot to process the Adapt Templates command
* @throws Exception test fails
*/
public static void runAndCaptureAdaptTemplatesSets(SWTWorkbenchBot bot) throws Exception {

ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time

SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
view.bot().tree().contextMenu("CobiGen").menu("Adapt Templates...").click();

SWTBotShell informationDialog = bot.shell("Information");
bot.waitUntil(new AnyShellIsActive("Information"), DEFAULT_TIMEOUT);
takeScreenshot(bot, "Adapt Templates Information");
informationDialog.bot().button("Ok").click();
}

/**
* Takes a screenshot (*.jpeg) of the current screen encoding test method and class and appends the given identifier
* to the file name
Expand Down
Loading