diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ExceptionHandlingTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ExceptionHandlingTest.java new file mode 100644 index 0000000000..eb0b288382 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ExceptionHandlingTest.java @@ -0,0 +1,73 @@ +package com.devonfw.cobigen.eclipse.test; + +import java.io.File; + +import org.apache.commons.io.FileUtils; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; +import com.devonfw.cobigen.eclipse.test.common.SystemTest; +import com.devonfw.cobigen.eclipse.test.common.utils.EclipseCobiGenUtils; +import com.devonfw.cobigen.eclipse.test.common.utils.EclipseUtils; + +/** + * Test suite for exception handling issues. + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class ExceptionHandlingTest extends SystemTest { + + /** Root path of the Test Resources */ + private static final String resourcesRootPath = "src/main/resources/ExceptionHandlingTest/"; + + /** + * Setup workbench appropriately for tests + * + * @throws Exception test fails + */ + @BeforeClass + public static void setupClass() throws Exception { + + EclipseUtils.cleanWorkspace(bot, true); + // import the configuration project for this test + EclipseUtils.importExistingGeneralProject(bot, new File(resourcesRootPath + "templates").getAbsolutePath()); + EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); + } + + /** + * Tests for a conflict of old and new templates configuration and proper error message dialog + * + * @throws Exception Test fails + */ + @Test + @Ignore + public void testConflictWithTemplateTypesDisplaysErrorDialog() throws Exception { + + // create a new temporary java project and copy java class used as an input for CobiGen + String testProjectName = "TestInputProj"; + IJavaProject project = this.tmpMavenProjectRule.createProject(testProjectName); + FileUtils.copyFile(new File(resourcesRootPath + "input/PlainInput.java"), + project.getUnderlyingResource().getLocation().append("src/main/java/main/PlainInput.java").toFile()); + project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + this.tmpMavenProjectRule.updateProject(); + + // expand the new file in the package explorer + SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); + SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjectName, "src/main/java", "main", + "PlainInput.java"); + javaClassItem.select(); + + // execute CobiGen + EclipseCobiGenUtils.processCobiGenWithExpectedError(bot, javaClassItem, "Invalid context configuration!"); + } + +} 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 ec9d8406cc..8bf3ca2252 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 @@ -46,6 +46,20 @@ public static void processCobiGen(SWTWorkbenchBot bot, SWTBotTreeItem input, Str processCobiGen(bot, input, DEFAULT_TIMEOUT, increments); } + /** + * Tries a Generate process with an expected error title. + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param expectedErrorTitle String of expected error title + * @throws Exception test fails + */ + public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTreeItem input, + String expectedErrorTitle) throws Exception { + + processCobiGenWithExpectedError(bot, input, DEFAULT_TIMEOUT, expectedErrorTitle); + } + /** * Expands multi layer nodes of following format: node1>node2>finalNode * @@ -109,6 +123,31 @@ public static void processCobiGen(SWTWorkbenchBot bot, SWTBotTreeItem input, int finishButton.click(); } + /** + * Tries a Generate process with an expected error title. + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param defaultTimeout timeout to be overwritten + * @param expectedErrorTitle String of expected error title + * @throws Exception test fails + */ + public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTreeItem input, int defaultTimeout, + String expectedErrorTitle) throws Exception { + + // Open generation wizard with new file as Input + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); + bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time + input.contextMenu("CobiGen").menu("Generate...").click(); + bot.waitUntil(new AnyShellIsActive(expectedErrorTitle), defaultTimeout); + + takeScreenshot(bot, "InvalidConfigurationDialog"); + + SWTBotButton finishButton = bot.button(IDialogConstants.OK_LABEL); + bot.waitUntil(widgetIsEnabled(bot.button())); + finishButton.click(); + } + /** * Checks the CobiGen HealthCheck and takes screenshots of it. * diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java index 288b1cc04a..26edf4f958 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java @@ -187,7 +187,7 @@ public static void cleanWorkspace(SWTWorkbenchBot bot, boolean cleanCobiGenConfi } break; } catch (Exception e) { - LOG.debug("An error occured while trying to delete project: {}", projectName); + LOG.debug("An error occured while trying to delete project: {}", projectName, e); Thread.sleep(500); if (i == maxRetries) { LOG.debug("Not able to cleanup the workspace after: {} retries", maxRetries); diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/input/PlainInput.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/input/PlainInput.java new file mode 100644 index 0000000000..fc3a6a09ec --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/input/PlainInput.java @@ -0,0 +1,5 @@ +package main; + +public class PlainInput { + +} diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/.project b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/.project new file mode 100644 index 0000000000..29f3bb6869 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/.project @@ -0,0 +1,23 @@ + + + CobiGen_Templates + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/logback.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/logback.xml new file mode 100644 index 0000000000..a7c9f7855e --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/logback.xml @@ -0,0 +1,17 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/pom.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/pom.xml new file mode 100644 index 0000000000..1246bdb412 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + com.devonfw.cobigen + templates-oasp + 1.0.0 + jar + CobiGen OASP Templates + + + 1.8 + 1.8 + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + + \ No newline at end of file diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/context.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/context.xml new file mode 100644 index 0000000000..5b73512da1 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/context.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/TestOutput.txt.ftl b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/TestOutput.txt.ftl new file mode 100644 index 0000000000..793aa682b0 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/TestOutput.txt.ftl @@ -0,0 +1 @@ +This is a test \ No newline at end of file diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/context.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/context.xml new file mode 100644 index 0000000000..5b73512da1 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/context.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/templates.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/templates.xml new file mode 100644 index 0000000000..ab128701e7 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/ExceptionHandlingTest/templates/src/main/templates/template1/templates.xml @@ -0,0 +1,11 @@ + + + +