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