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