1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components.template;
22
23 import java.io.File;
24 import java.net.URL;
25 import java.util.Map;
26
27 import junit.framework.TestCase;
28
29 /***
30 * Test case for BaseTemplateEngine
31 */
32 public class BaseTemplateEngineTest extends TestCase {
33
34 public void testGetThemePropsThroughFileSystem() throws Exception {
35
36 URL dummyResourceUrl = getClass().getResource("dummy.properties");
37 File dummyResourceFile = new File(dummyResourceUrl.getFile());
38 String themePropertiesDir = dummyResourceFile.getParent();
39
40 System.out.println("dummy resource url="+dummyResourceUrl);
41 System.out.println("resource file="+dummyResourceFile);
42 System.out.println("theme properties dir="+themePropertiesDir);
43
44 assertTrue(dummyResourceFile.exists());
45 assertNotNull(themePropertiesDir);
46
47 Template template = new Template(themePropertiesDir, "theme1", "template1");
48
49 TemplateEngine templateEngine = new InnerBaseTemplateEngine("themeThroughFileSystem.properties");
50 Map propertiesMap = templateEngine.getThemeProps(template);
51
52 assertNotNull(propertiesMap);
53 assertTrue(propertiesMap.size() > 0);
54
55 }
56
57 public void testGetThemePropsThroughClasspath() throws Exception {
58
59 Template template = new Template("org/apache/struts2/components/template", "theme1", "template2");
60 TemplateEngine templateEngine = new InnerBaseTemplateEngine("themeThroughClassPath.properties");
61 Map propertiesMap = templateEngine.getThemeProps(template);
62
63 assertNotNull(propertiesMap);
64 assertTrue(propertiesMap.size() > 0);
65 }
66
67 public class InnerBaseTemplateEngine extends BaseTemplateEngine {
68
69 private String themePropertiesFileName;
70
71 public InnerBaseTemplateEngine(String themePropertiesFileName) {
72 this.themePropertiesFileName = themePropertiesFileName;
73 }
74
75 protected String getSuffix() {
76 return "ftl";
77 }
78
79 public void renderTemplate(TemplateRenderingContext templateContext) throws Exception {
80 }
81
82 protected String getThemePropertiesFileName() {
83 return this.themePropertiesFileName;
84 }
85 }
86 }