01: package com.opensymphony.webwork.views;
02:
03: import com.opensymphony.webwork.components.template.*;
04: import com.opensymphony.webwork.config.Configuration;
05: import junit.framework.TestCase;
06:
07: /**
08: * TemplateEngineManagerTest
09: * Date: Sep 28, 2004 12:22:05 PM
10: *
11: * @author jcarreira
12: */
13: public class TemplateEngineManagerTest extends TestCase {
14: public void testTemplateTypeFromTemplateNameAndDefaults() {
15: Configuration.setConfiguration(new Configuration() {
16: public boolean isSetImpl(String name) {
17: return name
18: .equals(TemplateEngineManager.DEFAULT_TEMPLATE_TYPE_CONFIG_KEY);
19: }
20:
21: public Object getImpl(String aName)
22: throws IllegalArgumentException {
23: if (aName
24: .equals(TemplateEngineManager.DEFAULT_TEMPLATE_TYPE_CONFIG_KEY)) {
25: return "jsp";
26: }
27: return null;
28: }
29: });
30: TemplateEngine engine = TemplateEngineManager
31: .getTemplateEngine(new Template("/template", "simple",
32: "foo"), null);
33: assertTrue(engine instanceof JspTemplateEngine);
34: engine = TemplateEngineManager.getTemplateEngine(new Template(
35: "/template", "simple", "foo.vm"), null);
36: assertTrue(engine instanceof VelocityTemplateEngine);
37: }
38:
39: public void testTemplateTypeOverrides() {
40: TemplateEngine engine = TemplateEngineManager
41: .getTemplateEngine(new Template("/template", "simple",
42: "foo"), "ftl");
43: assertTrue(engine instanceof FreemarkerTemplateEngine);
44: engine = TemplateEngineManager.getTemplateEngine(new Template(
45: "/template", "simple", "foo.vm"), "ftl");
46: assertTrue(engine instanceof VelocityTemplateEngine);
47: engine = TemplateEngineManager.getTemplateEngine(new Template(
48: "/template", "simple", "foo.ftl"), "");
49: assertTrue(engine instanceof FreemarkerTemplateEngine);
50: }
51:
52: public void testTemplateTypeUsesDefaultWhenNotSetInConfiguration() {
53: TemplateEngine engine = TemplateEngineManager
54: .getTemplateEngine(new Template("/template", "simple",
55: "foo"), null);
56: Template template = new Template("/template", "simple", "foo."
57: + TemplateEngineManager.DEFAULT_TEMPLATE_TYPE);
58: TemplateEngine defaultTemplateEngine = TemplateEngineManager
59: .getTemplateEngine(template, null);
60: assertTrue(engine.getClass().equals(
61: defaultTemplateEngine.getClass()));
62: }
63:
64: protected void tearDown() throws Exception {
65: super.tearDown();
66: Configuration.setConfiguration(null);
67: }
68: }
|