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