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