1 package org.apache.turbine.services.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.turbine.services.TurbineServices;
26 import org.apache.turbine.test.BaseTurbineTest;
27
28 /***
29 * Tests the class mapping of the Template Service for screen,
30 * layout and navigation.
31 *
32 * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
33 * @version $Id: ClassTest.java 534527 2007-05-02 16:10:59Z tv $
34 */
35
36 public class ClassTest
37 extends BaseTurbineTest
38 {
39 private TemplateService ts = null;
40
41 public ClassTest(String name)
42 throws Exception
43 {
44 super(name, "/conf/test/TemplateService.properties");
45 ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
46 }
47
48 public static Test suite()
49 {
50 return new TestSuite(ClassTest.class);
51 }
52
53 public void testTemplateDefaults()
54 {
55
56 assertEquals("Default Page failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultPage());
57 assertEquals("Default Screen failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultScreen());
58 assertEquals("Default Layout failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayout());
59 assertEquals("Default Navigation failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultNavigation());
60 }
61
62 public void testVelocityDefaults()
63 {
64
65 assertEquals("Default Page failed", "VelocityPage", ts.getDefaultPageName("foo.vm"));
66 assertEquals("Default Screen failed", "VelocityScreen", ts.getDefaultScreenName("foo.vm"));
67 assertEquals("Default Layout failed", "VelocityOnlyLayout", ts.getDefaultLayoutName("foo.vm"));
68 assertEquals("Default Navigation failed", "VelocityNavigation", ts.getDefaultNavigationName("foo.vm"));
69 }
70
71
72
73 public void testNonExistingTemplate()
74 throws Exception
75 {
76
77
78
79
80 String templateName = "DoesNotExistPage.vm";
81 assertEquals("Screen translation failed", "VelocityScreen", ts.getScreenName(templateName));
82 assertEquals("Layout translation failed", "VelocityOnlyLayout", ts.getLayoutName(templateName));
83 assertEquals("Navigation translation failed", "VelocityNavigation", ts.getNavigationName(templateName));
84 }
85
86 public void testNonExistingSublevelTemplate()
87 throws Exception
88 {
89
90
91
92 String templateName = "this,template,DoesNotExistPage.vm";
93 assertEquals("Screen translation failed", "VelocityScreen", ts.getScreenName(templateName));
94 assertEquals("Layout translation failed", "VelocityOnlyLayout", ts.getLayoutName(templateName));
95 assertEquals("Navigation translation failed", "VelocityNavigation", ts.getNavigationName(templateName));
96 }
97
98 public void testExistingTemplate()
99 throws Exception
100 {
101
102
103 String templateName = "ExistPage.vm";
104 assertEquals("Screen translation failed", "VelocityScreen", ts.getScreenName(templateName));
105 assertEquals("Layout translation failed", "VelocityOnlyLayout", ts.getLayoutName(templateName));
106 assertEquals("Navigation translation failed", "VelocityNavigation", ts.getNavigationName(templateName));
107 }
108
109 public void testExistingSublevelTemplate()
110 throws Exception
111 {
112
113
114 String templateName = "existing,Page.vm";
115 assertEquals("Screen translation failed", "VelocityScreen", ts.getScreenName(templateName));
116 assertEquals("Layout translation failed", "VelocityOnlyLayout", ts.getLayoutName(templateName));
117 assertEquals("Navigation translation failed", "VelocityNavigation", ts.getNavigationName(templateName));
118 }
119
120
121
122 public void testExistingClass()
123 throws Exception
124 {
125
126
127
128
129 String templateName = "ExistPageWithClass.vm";
130 assertEquals("Screen translation failed", "ExistPageWithClass", ts.getScreenName(templateName));
131 assertEquals("Layout translation failed", "ExistPageWithClass", ts.getLayoutName(templateName));
132 assertEquals("Navigation translation failed", "ExistPageWithClass", ts.getNavigationName(templateName));
133 }
134
135 public void testExistingSublevelClass()
136 throws Exception
137 {
138
139
140
141
142
143 String templateName = "existing,PageWithClass.vm";
144 assertEquals("Screen translation failed", "existing.PageWithClass", ts.getScreenName(templateName));
145 assertEquals("Layout translation failed", "existing.PageWithClass", ts.getLayoutName(templateName));
146 assertEquals("Navigation translation failed", "existing.PageWithClass", ts.getNavigationName(templateName));
147 }
148
149 public void testDefaultClass()
150 throws Exception
151 {
152
153
154
155 String templateName = "existing,dflt,PageWithClass.vm";
156 assertEquals("Screen translation failed", "existing.dflt.Default", ts.getScreenName(templateName));
157 assertEquals("Layout translation failed", "existing.dflt.Default", ts.getLayoutName(templateName));
158 assertEquals("Navigation translation failed", "existing.dflt.Default", ts.getNavigationName(templateName));
159 }
160
161 public void testDefaultSublevelClass()
162 throws Exception
163 {
164
165
166
167 String templateName = "existing,dflt,onelevel,twolevel,threelevel,PageWithClass.vm";
168 assertEquals("Screen translation failed", "existing.dflt.Default", ts.getScreenName(templateName));
169 assertEquals("Layout translation failed", "existing.dflt.Default", ts.getLayoutName(templateName));
170 assertEquals("Navigation translation failed", "existing.dflt.Default", ts.getNavigationName(templateName));
171 }
172
173 public void testIgnoreExistingClass()
174 throws Exception
175 {
176
177
178
179
180 String templateName = "sublevel,ExistPageWithClass.vm";
181 assertEquals("Screen translation failed", "VelocityScreen", ts.getScreenName(templateName));
182 assertEquals("Layout translation failed", "VelocityOnlyLayout", ts.getLayoutName(templateName));
183 assertEquals("Navigation translation failed", "VelocityNavigation", ts.getNavigationName(templateName));
184 }
185
186
187 }