diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java index f1d6e334a7..c63f96bdf3 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java @@ -6,6 +6,7 @@ import java.io.File; import org.apache.commons.io.FileUtils; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; @@ -19,9 +20,11 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.api.util.CobiGenPaths; +import com.devonfw.cobigen.api.util.TemplatesJarUtil; import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; import com.devonfw.cobigen.eclipse.test.common.SystemTest; +import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished; import com.devonfw.cobigen.eclipse.test.common.utils.EclipseCobiGenUtils; import com.devonfw.cobigen.eclipse.test.common.utils.EclipseUtils; @@ -31,71 +34,81 @@ */ public class AdaptTemplatesTest extends SystemTest { - /** Temporary files rule to create temporary folders or files */ - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - /** Root path of the Test Resources */ - private static final String resourcesRootPath = "src/main/resources/OpenAPITest/"; - - /** Line separator, e.g. for windows '\r\n' */ - public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator"); - - /** - * Setup workbench appropriately for tests - * - * @throws Exception test fails - */ - @BeforeClass - public static void setupClass() throws Exception { - - EclipseUtils.cleanWorkspace(bot, true); - - } - - /** - * Test generation with OpenAPI input after adapting templates - * - * @throws Exception test fails - */ - public void testBasicOpenAPIGenerationWithAdaptTemplates() 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.runAndCaptureUpdateTemplates(bot); - EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); - EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); - - 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(); - - IProject adaptedTemplatesProj = ResourcesPlugin.getWorkspace().getRoot() - .getProject(ConfigurationConstants.COBIGEN_TEMPLATES); - - assertThat(adaptedTemplatesProj.exists()).isTrue(); - } - - /** - * Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME - * environment variable - * - * @throws Exception test fails - */ - @Test - public void testAdaptTemplates() throws Exception { - - File tmpProject = this.tempFolder.newFolder("playground", "project", "templates"); - withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, tmpProject.getParentFile().getAbsolutePath()) - .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates()); - } + /** Temporary files rule to create temporary folders or files */ + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + /** Root path of the Test Resources */ + private static final String resourcesRootPath = "src/main/resources/OpenAPITest/"; + + /** Line separator, e.g. for windows '\r\n' */ + public static final String LINE_SEPARATOR = java.lang.System.getProperty("line.separator"); + + /** + * Setup workbench appropriately for tests + * + * @throws Exception test fails + */ + @BeforeClass + public static void setupClass() throws Exception { + + EclipseUtils.cleanWorkspace(bot, true); + } + + /** + * Test for external projects (not in workspace) taken as input for generation + * + * @throws Exception test fails + */ + public void testBasicOpenAPIGenerationWithAdaptTemplates() 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(); + + File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile(); + TemplatesJarUtil.downloadLatestDevon4jTemplates(true, templatesDirectory); + TemplatesJarUtil.downloadLatestDevon4jTemplates(false, templatesDirectory); + EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); + EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); + + 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.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); + + 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 of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable + * + * @throws Exception test fails + */ + @Test + public void testAdaptTemplatesAndGenerate() throws Exception { + + File tmpProject = this.tempFolder.newFolder("playground", "project"); + withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString()) + .execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates()); + } } diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java index 5a7b97d195..e973dda4b4 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java @@ -394,10 +394,6 @@ public static void runAndCaptureAdaptTemplates(SWTWorkbenchBot bot) throws Excep SWTBotShell warningDialog = bot.shell("Warning!"); warningDialog.bot().button("Ok").click(); - takeScreenshot(bot, "Create new POM!"); - SWTBotShell finishDialog = bot.shell("Create new POM"); - finishDialog.bot().button("Finish").click(); - SWTBotShell informationDialog = bot.shell("Information"); bot.waitUntil(new AnyShellIsActive("Information"), DEFAULT_TIMEOUT); takeScreenshot(bot, "Adapt Templates Information"); diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java index ac34c79203..0b842712b7 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java @@ -13,9 +13,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; -import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; -import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.MessageDialog; @@ -24,12 +21,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - import com.devonfw.cobigen.api.TemplateAdapter; import com.devonfw.cobigen.api.constants.ConfigurationConstants; import com.devonfw.cobigen.api.util.CobiGenPaths; import com.devonfw.cobigen.api.util.TemplatesJarUtil; +import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; +import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; +import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog; import com.devonfw.cobigen.impl.CobiGenFactory; import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; @@ -261,7 +259,7 @@ public static void processJar(String fileName) throws MalformedURLException, IOE } try { - TemplateAdapter templateAdapter = new TemplateAdapterImpl(cobigenFolderPath); + TemplateAdapter templateAdapter = new TemplateAdapterImpl(null); templateAdapter.adaptMonolithicTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES), false); } catch (Exception e) { @@ -298,7 +296,6 @@ public static void startTemplatesUpgrader(Path configurationPath) { setTemplateSetPathAfterUpgrade(CobiGenFactory.startTemplatesUpgrader(configurationPath)); - // FIXME after the upgrade adapt the new template-set folder. should be done in #1587 } diff --git a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java index c2178fb3b2..964ad964ac 100644 --- a/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java +++ b/cobigen/cobigen-core-api/src/main/java/com/devonfw/cobigen/api/util/CobiGenPaths.java @@ -75,7 +75,9 @@ public static Path getTemplatesFolderPath() { public static Path getTemplatesFolderPath(Path home) { Path templatesPath = home.resolve(ConfigurationConstants.TEMPLATES_FOLDER); - return templatesPath; + + return createFolder(templatesPath); + } /**