This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ed8bb6  Add tests for CAY-2729 Unable to use custom templates from a 
folder at upper level then datamap
     new a54bea8  Merge pull request #490 from 
Ivan-nikitko/Test_for_bug_with_tempates_relative_path_in_modeler
1ed8bb6 is described below

commit 1ed8bb639f7214862814be96d14eed710dd3778a
Author: ivannikitka <nikitko.i...@gmail.com>
AuthorDate: Mon Jan 24 17:20:17 2022 +0300

    Add tests for CAY-2729 Unable to use custom templates from a folder at 
upper level then datamap
---
 .../apache/cayenne/gen/ClassGenerationAction.java  |  2 +-
 .../apache/cayenne/gen/TemplateLocationTest.java   | 50 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index 5b10cdb..6429f9d 100644
--- 
a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ 
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -295,7 +295,7 @@ public class ClassGenerationAction {
                }
        }
 
-       private Template getTemplate(TemplateType type) {
+        Template getTemplate(TemplateType type) {
 
                String templateName = customTemplateName(type);
                if (templateName == null) {
diff --git 
a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/TemplateLocationTest.java 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/TemplateLocationTest.java
new file mode 100644
index 0000000..40d6df8
--- /dev/null
+++ 
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/TemplateLocationTest.java
@@ -0,0 +1,50 @@
+package org.apache.cayenne.gen;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.nio.file.Paths;
+
+import static org.junit.Assert.assertNotNull;
+
+public class TemplateLocationTest {
+
+    @Rule
+    public TemporaryFolder tempFolder = new TemporaryFolder();
+    private CgenConfiguration cgenConfiguration;
+    private ClassGenerationAction action;
+    private TemplateType templateType;
+
+    @Before
+    public void setUp() {
+        cgenConfiguration = new CgenConfiguration(false);
+        action = new ClassGenerationAction(cgenConfiguration);
+        templateType = TemplateType.ENTITY_SUBCLASS;
+    }
+
+    @Test
+    public void upperLevel() throws Exception {
+        cgenConfiguration.setRootPath(tempFolder.newFolder().toPath());
+        tempFolder.newFile("testTemplate.vm");
+        cgenConfiguration.setTemplate("../testTemplate.vm");
+        assertNotNull(action.getTemplate(templateType));
+    }
+
+    @Test
+    public void sameLevel() throws Exception {
+        cgenConfiguration.setRootPath(tempFolder.getRoot().toPath());
+        tempFolder.newFile("testTemplate2.vm");
+        cgenConfiguration.setTemplate("testTemplate2.vm");
+        assertNotNull(action.getTemplate(templateType));
+    }
+
+    @Test
+    public void aboveLevel() throws Exception {
+        
cgenConfiguration.setRootPath(Paths.get(tempFolder.getRoot().getParent()));
+        tempFolder.newFile("testTemplate3.vm");
+        cgenConfiguration.setTemplate(tempFolder.getRoot() + 
"/testTemplate3.vm");
+        assertNotNull(action.getTemplate(templateType));
+    }
+}

Reply via email to