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