-
Notifications
You must be signed in to change notification settings - Fork 70
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 #1654
base: master
Are you sure you want to change the base?
Changes from all commits
6f5e2ce
e258c4b
ad233ff
54e3436
36ab7ce
a39ec1c
4e4b6d3
a1ca29a
6c61401
882013e
103ed1c
28cb652
54f0bca
51af790
b5a2577
7b6bf79
3dcfcb1
f95f041
2ee15d3
f20d731
9b96780
9bd84b8
7a3b6e4
5f79726
7daa568
c95a9df
0176c1a
edaed0e
0ddc3bc
f4794fd
f1ad8d7
0d61fda
1d8997a
efd512e
5e1a7e3
f73d720
4f9da87
fbb5331
1ded60f
dc72408
b597945
e4f9a00
efdc183
b76c231
9dbe233
9aed99a
eb8c1c1
03d219b
49ae604
556cff8
199c84d
4e097f8
e7ad216
8ab4a8d
f4a9ebc
f339117
81e95c3
2c1db7f
72d89a8
86122c8
357a938
d939f03
81c4d15
e6a2a72
e8e0ce4
fc6fc18
35ac03e
f854bf1
fbda14e
67fdce9
dd94bab
e28e03b
8918a9f
3e655e1
67de615
0fbb14c
c10ccce
a6949e0
715a962
ed9670c
be0cd10
f9e8152
d9758cb
033d462
e4843bd
65891b7
b498c23
b971f77
c8c7898
9ff3ba5
10ffe53
1140415
8e435a4
2208391
c66cdab
3e65ddf
40bd436
62eb061
85e44ba
94cd277
2260ee6
5f0588b
b2b328e
514b1e6
340b569
a53b75d
485d5a4
9148d62
2e794bd
a01765e
faee4f1
a32120b
cd38c95
2b1360d
ead77d6
3b92e6f
8318b2a
e15f077
587f983
5ca8f21
177f9d3
f41220b
694b0c9
bfb5536
f75dfe7
91edfcc
2c440e2
9d7ca6d
21b3f71
167a978
35f5d1a
472ea6e
b3dc966
9112b26
65b988e
9625a53
f251ea3
edc17c7
7c1c6af
0f8b48b
654499f
b264377
d522e05
abbac3e
28d91bc
0b79b14
af182c4
ef61c78
8e5cf73
cd5a294
bf97608
0ecb4e4
9f31845
fcfc0e8
3314e71
151698e
0c07125
fb9ba81
540abee
39aa279
0c28780
da1f980
52f4f85
bc64317
d68fc46
4bf5ca9
217c8a4
beb7248
1a081e2
f163973
64683ab
27dced6
07e7ad8
b045ea2
b34d7e6
82d0ad4
ac2efa9
e79d214
a5757ff
75adfe4
a51ee91
b5574a1
c5e9d33
b98e202
ae0c108
0611e0f
5113482
b421049
a25b371
01ef924
950aaa7
28f53b0
6a1e6f9
ad76aea
980e893
02bdb62
26b6c2c
2012d11
28ce188
f54e6c3
e3469e8
f3de717
f7f16ec
677ea7c
4d728ba
f3a4399
ed156b2
79f94e8
587b2e9
08e7892
5af0844
1b49fb0
c4ce99d
6ae0954
3ef6f64
deb68b6
ee90c8b
5983e65
c0c39c4
e82340a
2a96c00
52ba0fb
a2a4137
676ac3e
d57a660
5c64a1e
ba8f1b9
d091ce0
ebd5dec
bb245f1
682538e
7c4d31b
35ca10a
603c105
de4177b
58cf2c9
5821c9d
8d68916
2219f4a
0eeb9d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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 | ||
* | ||
|
@@ -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. | ||
*/ | ||
// EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot); | ||
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed as there will be no update functionality in Eclipse anymore. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description does not fit. |
||
* | ||
* @throws Exception test fails | ||
*/ | ||
public void testAdaptTemplatesAndImportIntoEclipse() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Template-sets? |
||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove or re-enable. |
||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove or re-enable. |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description does not fit. |
||
* | ||
* @throws Exception test fails | ||
*/ | ||
public void testBasicOpenAPIGenerationWithAdaptMonolithicTemplates() throws Exception { | ||
|
||
// copy sample project to external location and import it into the workspace | ||
String testProjName = "ExtTestProj"; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this removed? |
||
EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); | ||
EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); | ||
|
||
|
@@ -93,7 +179,6 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { | |
|
||
// execute CobiGen | ||
EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "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); | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check this description. |
||
* | ||
* @throws Exception test fails | ||
*/ | ||
@Test | ||
public void testAdaptTemplatesAndGenerate() throws Exception { | ||
@Ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignored? |
||
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -361,7 +362,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()); | ||
Comment on lines
+365
to
+366
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed? |
||
bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time | ||
|
||
SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); | ||
|
@@ -402,6 +404,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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.devonfw.test</groupId> | ||
<artifactId>crud-java-server-app</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<outputDirectory>../../downloaded</outputDirectory> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<skipSource>${skip.deployment}</skipSource> | ||
<outputDirectory>../../downloaded</outputDirectory> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<!-- Inject Maven Properties in java-templates source folder --> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>templating-maven-plugin</artifactId> | ||
<version>1.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>generate-maven-properties-class</id> | ||
<goals> | ||
<goal>filter-sources</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<tasks> | ||
<echo>Integrate POM manually</echo> | ||
<copy file="pom.xml" tofile="${project.build.outputDirectory}/pom.xml"/> | ||
</tasks> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test description does not fit.