diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java index 3d632b8f68..5583ca723e 100644 --- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java +++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java @@ -75,14 +75,12 @@ public void generateFromEntityTest() throws Exception { * @throws Exception test fails */ @Test - @Ignore // TODO: re-enable when upgrade process is implemented, see: https://github.com/devonfw/cobigen/issues/1595 public void upgradeAndGenerateFromEntityTest() throws Exception { - FileUtils.copyDirectory(new File(testFileRootPath + "templatesproject"), this.tmpProject.toFile()); - this.tmpProject.resolve("templates-devon4j").toFile() - .renameTo(this.tmpProject.resolve(ConfigurationConstants.COBIGEN_TEMPLATES).toFile()); + FileUtils.copyDirectory(new File(testFileRootPath + "templatesproject/templates-devon4j"), + this.currentHome.toFile().toPath().resolve(ConfigurationConstants.COBIGEN_TEMPLATES).toFile()); File baseProject = this.tmpProject.resolve("maven.project/core/").toFile(); - File monolithicConfiguration = this.tmpProject.toFile(); + File monolithicConfiguration = this.currentHome.toFile(); String args[] = new String[7]; args[0] = "generate"; args[1] = this.entityInputFile.getAbsolutePath(); @@ -95,6 +93,7 @@ public void upgradeAndGenerateFromEntityTest() throws Exception { execute(args, false); assertThat(this.currentHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)).exists(); + assertThat(this.currentHome.resolve(ConfigurationConstants.BACKUP_FOLDER)).exists(); assertThat(baseProject.toPath().resolve("src/main/java/com/maven/project/sampledatamanagement/logic/api/to")) .exists(); diff --git a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationIT.java b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationIT.java index 7ce25f2ce5..4b775b7a84 100644 --- a/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationIT.java +++ b/cobigen/cobigen-core-systemtest/src/test/java/com/devonfw/cobigen/systemtest/GenerationIT.java @@ -26,6 +26,8 @@ import org.mockito.ArgumentMatchers; import com.devonfw.cobigen.api.CobiGen; +import com.devonfw.cobigen.api.TemplateAdapter; +import com.devonfw.cobigen.api.exception.DeprecatedMonolithicConfigurationException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.extension.GeneratorPluginActivator; import com.devonfw.cobigen.api.extension.InputReader; @@ -37,6 +39,7 @@ import com.devonfw.cobigen.api.to.MatcherTo; import com.devonfw.cobigen.api.to.TemplateTo; import com.devonfw.cobigen.impl.CobiGenFactory; +import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; import com.devonfw.cobigen.impl.extension.PluginRegistry; import com.devonfw.cobigen.impl.model.ModelBuilderImpl; import com.devonfw.cobigen.systemtest.common.AbstractApiTest; @@ -81,6 +84,46 @@ public void testOverrideMergeStrategy() throws Exception { assertThat(target).hasContent("overwritten"); } + /** + * Tests if after a upgrade with a merge of context and templates to template sets a generation of all matching (java) + * templates is successful + * + * @throws Exception test fails. + */ + @Test + public void testUpgradeAndGenerateWithJavaInput() throws Exception { + + File templates = this.tmpFolder.newFolder("templates"); + FileUtils.copyDirectory(new File(testFileRootPath + "UpgradeTest/templates"), templates); + CobiGen cobigen = null; + assertThatThrownBy(() -> { + CobiGenFactory.create(templates.toURI()); + }).isInstanceOf(DeprecatedMonolithicConfigurationException.class); + + TemplateAdapter templateAdapter = new TemplateAdapterImpl(templates.toPath()); + Path templateSets = templateAdapter.upgradeMonolithicTemplates(templates.toPath()); + cobigen = CobiGenFactory.create(templateSets.getParent().toUri()); + Object input = cobigen.read( + new File("src/test/java/com/devonfw/cobigen/systemtest/testobjects/io/generator/logic/api/to/InputEto.java") + .toPath(), + Charset.forName("UTF-8"), getClass().getClassLoader()); + + File folder = this.tmpFolder.newFolder("GenerationTest"); + File target = new File(folder, "generated.txt"); + FileUtils.write(target, "base"); + + List templatesTos = cobigen.getMatchingTemplates(input); + List increments = cobigen.getMatchingIncrements(input); + List triggersIds = cobigen.getMatchingTriggerIds(input); + assertThat(templatesTos).hasSize(1); + assertThat(increments).hasSize(1); + assertThat(triggersIds).hasSize(1); + + GenerationReportTo report1 = cobigen.generate(input, templatesTos.get(0), Paths.get(folder.toURI())); + + assertThat(report1).isSuccessful(); + } + /** * Tests that multiple template sets with templates, increments and triggers get read and generate of all matching * (java) templates is successful diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/pom.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/pom.xml new file mode 100644 index 0000000000..79e6e7b9c3 --- /dev/null +++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + com.devonfw.test + templates-devon4j + dev-SNAPSHOT + jar + + 1.8 + 1.8 + + + + + org.apache.commons + commons-math3 + 3.6.1 + + + + + + + src/main/templates + src/main/templates + + + + + org.codehaus.mojo + flatten-maven-plugin + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-package + + run + + + + Integrate POM manually + + + + + + + + + + \ No newline at end of file diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/context.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/context.xml new file mode 100644 index 0000000000..19358f4fee --- /dev/null +++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/context.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/template-test/templates.xml b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/template-test/templates.xml new file mode 100644 index 0000000000..d5b84d8bcd --- /dev/null +++ b/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTest/UpgradeTest/templates/CobiGen_Templates/src/main/templates/template-test/templates.xml @@ -0,0 +1,13 @@ + + +