01: /*
02: * $Id: BaseTemplateEngineTest.java 541676 2007-05-25 14:48:33Z apetrelli $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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(
37: "dummy.properties");
38: File dummyResourceFile = new File(dummyResourceUrl.getFile()
39: .replaceAll("%20", " "));
40: String themePropertiesDir = dummyResourceFile.getParent();
41:
42: System.out.println("dummy resource url=" + dummyResourceUrl);
43: System.out.println("resource file=" + dummyResourceFile);
44: System.out
45: .println("theme properties dir=" + themePropertiesDir);
46:
47: assertTrue(dummyResourceFile.exists());
48: assertNotNull(themePropertiesDir);
49:
50: Template template = new Template(themePropertiesDir, "theme1",
51: "template1");
52:
53: TemplateEngine templateEngine = new InnerBaseTemplateEngine(
54: "themeThroughFileSystem.properties");
55: Map propertiesMap = templateEngine.getThemeProps(template);
56:
57: assertNotNull(propertiesMap);
58: assertTrue(propertiesMap.size() > 0);
59:
60: }
61:
62: public void testGetThemePropsThroughClasspath() throws Exception {
63:
64: Template template = new Template(
65: "org/apache/struts2/components/template", "theme1",
66: "template2");
67: TemplateEngine templateEngine = new InnerBaseTemplateEngine(
68: "themeThroughClassPath.properties");
69: Map propertiesMap = templateEngine.getThemeProps(template);
70:
71: assertNotNull(propertiesMap);
72: assertTrue(propertiesMap.size() > 0);
73: }
74:
75: public class InnerBaseTemplateEngine extends BaseTemplateEngine {
76:
77: private String themePropertiesFileName;
78:
79: public InnerBaseTemplateEngine(String themePropertiesFileName) {
80: this .themePropertiesFileName = themePropertiesFileName;
81: }
82:
83: protected String getSuffix() {
84: return "ftl";
85: }
86:
87: public void renderTemplate(
88: TemplateRenderingContext templateContext)
89: throws Exception {
90: }
91:
92: protected String getThemePropertiesFileName() {
93: return this.themePropertiesFileName;
94: }
95: }
96: }
|