KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > template > TemplateTest


1 package org.apache.turbine.services.template;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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 all the various template mappings for Screen and Layout
27  * templates of the template service.
28  *
29  * @author <a HREF="hps@intermeta.de">Henning P. Schmiedehausen</a>
30  * @version $Id: TemplateTest.java,v 1.4.2.3 2004/08/14 20:57:58 henning Exp $
31  */

32
33 public class TemplateTest
34     extends BaseTurbineTest
35 {
36     private static TemplateService ts = null;
37
38     public TemplateTest(String JavaDoc name)
39             throws Exception JavaDoc
40     {
41         super(name, "/conf/test/TemplateService.properties");
42
43         ts = (TemplateService) TurbineServices.getInstance().getService(TemplateService.SERVICE_NAME);
44     }
45
46     public static Test suite()
47     {
48         return new TestSuite(TemplateTest.class);
49     }
50
51     public void testTemplateDefaults()
52     {
53         assertEquals("Default LayoutTemplate failed", TemplateService.DEFAULT_TEMPLATE_VALUE, ts.getDefaultLayoutTemplate());
54     }
55
56     public void testVelocityDefaults()
57     {
58         assertEquals("Default LayoutTemplate failed", "Default.vm", ts.getDefaultLayoutTemplateName("foo.vm"));
59     }
60
61     public void testNonExistingTemplate()
62         throws Exception JavaDoc
63     {
64         //
65
// Try a non existing Template. This should render with the default screen class,
66
// use the default Layout class and Navigation. It should be rendered with the
67
// default Layout Template but the Screen Template itself must not exist.
68
String JavaDoc templateName = "DoesNotExistPage.vm";
69         assertEquals("LayoutTemplate translation failed", "Default.vm", ts.getLayoutTemplateName(templateName));
70         assertEquals("ScreenTemplate translation failed", null, ts.getScreenTemplateName(templateName));
71     }
72
73     public void testNonExistingSublevelTemplate()
74         throws Exception JavaDoc
75     {
76         //
77
// Try a non existing Template in a sub-path. This should render with the default screen class,
78
// use the default Layout class and Navigation. It should be rendered with the
79
// default Layout Template but the Screen Template itself must not exist.
80
String JavaDoc templateName = "this,template,DoesNotExistPage.vm";
81         assertEquals("LayoutTemplate translation failed", "Default.vm", ts.getLayoutTemplateName(templateName));
82         assertEquals("ScreenTemplate translation failed", null, ts.getScreenTemplateName(templateName));
83     }
84
85     public void testExistingTemplate()
86         throws Exception JavaDoc
87     {
88         //
89
// Try an existing Template. As we already know, missing classes are found correctly
90
// so we test only Layout and Screen template. This should return the "Default" Layout
91
// template to render and the Screen Template for the Page to render
92
String JavaDoc templateName = "ExistPage.vm";
93         assertEquals("LayoutTemplate translation failed", "Default.vm", ts.getLayoutTemplateName(templateName));
94         assertEquals("ScreenTemplate translation failed", "ExistPage.vm", ts.getScreenTemplateName(templateName));
95     }
96
97     public void testExistingSublevelTemplate()
98         throws Exception JavaDoc
99     {
100         //
101
// Try an existing Template. As we already know, missing classes are found correctly
102
// so we test only Layout and Screen template. This should return the "Default" Layout
103
// template to render and the Screen Template for the Page to render. The names returned
104
// by the template service are "/" separated so that e.g. Velocity can use this.
105
String JavaDoc templateName = "existing,Page.vm";
106         assertEquals("LayoutTemplate translation failed", "Default.vm", ts.getLayoutTemplateName(templateName));
107         assertEquals("ScreenTemplate translation failed", "existing/Page.vm", ts.getScreenTemplateName(templateName));
108     }
109
110     public void testExistingLayoutTemplate()
111         throws Exception JavaDoc
112     {
113         //
114
// Try an existing Template. This time we have a backing Layout page. So the getLayoutTemplateName
115
// method should not return the Default but our Layout page.
116
//
117
String JavaDoc templateName = "ExistPageWithLayout.vm";
118         assertEquals("LayoutTemplate translation failed", "ExistPageWithLayout.vm", ts.getLayoutTemplateName(templateName));
119         assertEquals("ScreenTemplate translation failed", "ExistPageWithLayout.vm", ts.getScreenTemplateName(templateName));
120     }
121
122     public void testExistingSublevelLayoutTemplate()
123         throws Exception JavaDoc
124     {
125         //
126
// Try an existing Template. This time we have a backing Layout page. So the getLayoutTemplateName
127
// method should not return the Default but our Layout page.
128
//
129
String JavaDoc templateName = "existing,ExistSublevelPageWithLayout.vm";
130         assertEquals("LayoutTemplate translation failed", "existing/ExistSublevelPageWithLayout.vm", ts.getLayoutTemplateName(templateName));
131         assertEquals("ScreenTemplate translation failed", "existing/ExistSublevelPageWithLayout.vm", ts.getScreenTemplateName(templateName));
132     }
133
134     public void testExistingDefaultLayoutTemplate()
135         throws Exception JavaDoc
136     {
137         //
138
// Try an existing Template in a sublevel. This has an equally named Layout in the root. This
139
// test must find the Template itself but the "Default" layout
140
//
141
String JavaDoc templateName = "existing,ExistPageWithLayout.vm";
142         assertEquals("LayoutTemplate translation failed", "Default.vm", ts.getLayoutTemplateName(templateName));
143         assertEquals("ScreenTemplate translation failed", "existing/ExistPageWithLayout.vm", ts.getScreenTemplateName(templateName));
144     }
145 }
146
147
Popular Tags