diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/java/com/devonfw/cobigen/maven/systemtest/TemplatePluginLoadtest.java b/cobigen-maven/cobigen-maven-systemtest/src/test/java/com/devonfw/cobigen/maven/systemtest/TemplatePluginLoadtest.java new file mode 100644 index 0000000000..15d35f3794 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/java/com/devonfw/cobigen/maven/systemtest/TemplatePluginLoadtest.java @@ -0,0 +1,34 @@ +package com.devonfw.cobigen.maven.systemtest; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.nio.file.Files; + +import org.junit.Test; + +import com.devonfw.cobigen.maven.systemtest.config.constant.MavenMetadata; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; + +/** + * TODO alsaad This type ... + * + */ +public class TemplatePluginLoadtest extends AbstractMavenTest { + + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/systemtest/Devon4JTemplateTest/"; + + @Test + public void testPluginsFromPom() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestProject/"); + File templatesProject = new File(TEST_RESOURCES_ROOT, "TestTemplatesProjectForPom"); + File testProjectRoot = runMavenInvoker(testProject, templatesProject, MavenMetadata.LOCAL_REPO); + + assertThat(testProjectRoot.list()).containsOnly("pom.xml", "src", "target"); + long numFilesInSrc = Files.walk(testProjectRoot.toPath().resolve("src")).filter(Files::isRegularFile).count(); + // 1 from tos + assertThat(numFilesInSrc).isEqualTo(1); + } + +} diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/pom.xml b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/pom.xml new file mode 100644 index 0000000000..c06c135467 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + com.devonfw.test + Devon4JTemplateTest-TestEntityInputDataaccessGeneration + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject}/ + + src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java + + + tos + + + + + + + + diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java new file mode 100644 index 0000000000..e2d76c7c9f --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestProject/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.dataaccess.api; + +public class InputEntity { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/pom.xml b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/pom.xml new file mode 100644 index 0000000000..92531d04d5 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + com.devonfw.test + templates-devon4j + 3.1.8 + CobiGen devon4j Templates + CobiGen devon4j Templates + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + + + 1.8 + 1.8 + + + + + + src/main/templates + src/main/templates + + + + \ No newline at end of file diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/context.xml b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/context.xml new file mode 100644 index 0000000000..8e8d9e8288 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/context.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/functions.ftl b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/functions.ftl new file mode 100644 index 0000000000..f872e12b87 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/functions.ftl @@ -0,0 +1,140 @@ +<#-- -------------------- --> +<#-- devonfw SPECIFIC MACROS --> +<#-- -------------------- --> + +<#-- + Generates all field declaration whereas Entity references will be converted to appropriate id references +--> +<#macro generateFieldDeclarations_withRespectTo_entityObjectToIdReferenceConversion isSearchCriteria=false> +<#list pojo.fields as field> +<#if field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references --> + <#if !JavaUtil.isCollection(classObject, field.name)> <#-- do not generate field for multiple relation --> + private ${field.type?replace("[^<>,]+Entity","Long","r")} ${DevonfwUtil.resolveIdVariableName(classObject,field)}; + +<#elseif field.type?contains("Embeddable")> + <#if isSearchCriteria> + private ${field.type?replace("Embeddable","SearchCriteriaTo")} ${field.name}; + <#else> + private ${field.type?replace("Embeddable","Eto")} ${field.name}; + +<#elseif isSearchCriteria && JavaUtil.equalsJavaPrimitive(classObject,field.name)> + private ${JavaUtil.boxJavaPrimitives(classObject,field.name)} ${field.name}; +<#elseif !isSearchCriteria || !JavaUtil.isCollection(classObject, field.name)> + private ${field.type} ${field.name}; + + +<#-- Used to generate StringSearchConfigTo for each field --> +<#if isSearchCriteria> + <#list pojo.fields as field> + <#if field.type="String"> + private StringSearchConfigTo ${field.name}Option; + + + + + +<#-- + Generates all setter and getter for the fields whereas for Entity fields it will generate setter and getter for id references +--> +<#macro generateSetterAndGetter_withRespectTo_entityObjectToIdReferenceConversion implementsInterface=true, isInterface=false, isSearchCriteria=false> +<#list pojo.fields as field> +<#if field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references --> + <#if !JavaUtil.isCollection(classObject, field.name)> <#-- do not generate getters & setters for multiple relation --> + <#assign idVar = DevonfwUtil.resolveIdVariableName(classObject,field)> + <#if !implementsInterface> + /** + * getter for ${field.name}Id attribute + * @return ${field.name}Id + */ + + <#if implementsInterface>@Override + public ${DevonfwUtil.getSimpleEntityTypeAsLongReference(field)} ${DevonfwUtil.resolveIdGetter(field,false,"")} <#if isInterface>;<#else>{ + return ${idVar}; + } + <#if !implementsInterface> + /** + * @param ${field.name} + * setter for ${field.name} attribute + */ + + <#if implementsInterface>@Override + public void ${DevonfwUtil.resolveIdSetter(field,false,"")}(${DevonfwUtil.getSimpleEntityTypeAsLongReference(field)} ${idVar}) <#if isInterface>;<#else>{ + this.${idVar} = ${idVar}; + } + +<#elseif field.type?contains("Embeddable")> + <#if isSearchCriteria> + /** + * @return ${field.name} + */ + public ${field.type?replace("Embeddable","SearchCriteriaTo")} get${field.name?cap_first}() <#if isInterface>;<#else>{ + return ${field.name}; + } + + /** + * @param ${field.name} + * setter for ${field.name} attribute + */ + public void set${field.name?cap_first}(${field.type?replace("Embeddable","SearchCriteriaTo")} ${field.name}) <#if isInterface>;<#else>{ + this.${field.name} = ${field.name}; + } + <#else> + /** + * @return ${field.name}Id + */ + public ${field.type?replace("Embeddable","")} <#if field.type=='boolean'>is<#else>get${field.name?cap_first}() <#if isInterface>;<#else>{ + return ${field.name}; + } + + /** + * @param ${field.name} + * setter for ${field.name} attribute + */ + public void set${field.name?cap_first}(${field.type?replace("Embeddable","")} ${field.name}) <#if isInterface>;<#else>{ + this.${field.name} = ${field.name}; + } + +<#elseif !isSearchCriteria || !JavaUtil.isCollection(classObject, field.name)> + <#if !implementsInterface> + /** + * @return ${field.name}Id + */ + + <#if implementsInterface>@Override + public <#if isSearchCriteria>${JavaUtil.boxJavaPrimitives(classObject,field.name)} get${field.name?cap_first}() <#else>${field.type} <#if field.type=='boolean'>is<#else>get${field.name?cap_first}() <#if isInterface>;<#else>{ + return ${field.name}; + } + <#if !implementsInterface> + /** + * @param ${field.name} + * setter for ${field.name} attribute + */ + + <#if implementsInterface>@Override + public void set${field.name?cap_first}(<#if isSearchCriteria>${JavaUtil.boxJavaPrimitives(classObject,field.name)}<#else>${field.type} ${field.name}) <#if isInterface>;<#else>{ + this.${field.name} = ${field.name}; + } + + +<#if isSearchCriteria> + <#list pojo.fields as field> + <#if field.type="String"> + /** + * @return the {@link StringSearchConfigTo} used to search for {@link #get${field.name?cap_first}<#if field.type?contains("Entity")>Entity() ${field.name}}. + */ + public StringSearchConfigTo get${field.name?cap_first}Option() { + + return this.${field.name}Option; + } + + /** + * @param ${field.name}Option new value of {@link #get${field.name?cap_first}Option()}. + */ + public void set${field.name?cap_first}Option(StringSearchConfigTo ${field.name}Option) { + + this.${field.name}Option =${field.name}Option; + } + + + + diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates.xml b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates.xml new file mode 100644 index 0000000000..1c3bdc06ec --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl new file mode 100644 index 0000000000..9ae43a89e5 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl @@ -0,0 +1,86 @@ +<#include '/functions.ftl'> +package ${variables.rootPackage}.${variables.component}.logic.api.to; + +import com.devonfw.module.basic.common.api.to.AbstractEto; +import ${variables.rootPackage}.${variables.component}.common.api.${variables.entityName}; + +import java.util.List; +import java.util.Set; + +/** + * Entity transport object of ${variables.entityName} + */ +public class ${variables.entityName}Eto extends <#if pojo.extendedType.canonicalName=="java.lang.Object" || pojo.extendedType.package!=pojo.package || pojo.extendedType.name == "ApplicationPersistenceEntity">AbstractEto<#else>${pojo.extendedType.name?replace("Entity","Eto")} implements ${variables.entityName} { + + private static final long serialVersionUID = 1L; + + <@generateFieldDeclarations_withRespectTo_entityObjectToIdReferenceConversion/> + + <@generateSetterAndGetter_withRespectTo_entityObjectToIdReferenceConversion/> + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + <#if pojo.fields?has_content> + <#list pojo.fields as field> + <#if JavaUtil.equalsJavaPrimitive(classObject,field.name)> + result = prime * result + ${JavaUtil.castJavaPrimitives(classObject,field.name)}.hashCode(); + <#elseif field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references --> + <#if !field.type?starts_with("List<") && !field.type?starts_with("Set<")> + <#assign idVar = DevonfwUtil.resolveIdVariableName(classObject,field)> + result = prime * result + ((this.${idVar} == null) ? 0 : this.${idVar}.hashCode()); + + <#else> + result = prime * result + ((this.${field.name} == null) ? 0 : this.${field.name}.hashCode()); + + + <#else> + result = prime * result; + + return result; + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + // class check will be done by super type EntityTo! + if (!super.equals(obj)) { + return false; + } + ${variables.entityName}Eto other = (${variables.entityName}Eto) obj; + <#list pojo.fields as field> + <#if JavaUtil.equalsJavaPrimitive(classObject,field.name)> + if(this.${field.name} != other.${field.name}) { + return false; + } + <#elseif field.type?contains("Entity")> <#-- add ID getter & setter for Entity references only for ID references --> + <#if !field.type?starts_with("List<") && !field.type?starts_with("Set<")> + <#assign idVar = DevonfwUtil.resolveIdVariableName(classObject,field)> + if (this.${idVar} == null) { + if (other.${idVar} != null) { + return false; + } + } else if(!this.${idVar}.equals(other.${idVar})){ + return false; + } + + <#else> + if (this.${field.name} == null) { + if (other.${field.name} != null) { + return false; + } + } else if(!this.${field.name}.equals(other.${field.name})){ + return false; + } + + + return true; + } +} diff --git a/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties new file mode 100644 index 0000000000..393be96168 --- /dev/null +++ b/cobigen-maven/cobigen-maven-systemtest/src/test/resources/testdata/systemtest/Devon4JTemplateTest/TestTemplatesProjectForPom/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties @@ -0,0 +1 @@ +relocate:../api/src/main/${cwd} \ No newline at end of file