001: package org.apache.turbine.services.template;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import org.apache.turbine.services.TurbineServices;
023: import org.apache.turbine.test.BaseTurbineTest;
024:
025: /**
026: * Tests the class mapping of the Template Service for screen,
027: * layout and navigation.
028: *
029: * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
030: * @version $Id: ClassTest.java 264148 2005-08-29 14:21:04Z henning $
031: */
032:
033: public class ClassTest extends BaseTurbineTest {
034: private TemplateService ts = null;
035:
036: public ClassTest(String name) throws Exception {
037: super (name, "/conf/test/TemplateService.properties");
038: ts = (TemplateService) TurbineServices.getInstance()
039: .getService(TemplateService.SERVICE_NAME);
040: }
041:
042: public static Test suite() {
043: return new TestSuite(ClassTest.class);
044: }
045:
046: public void testTemplateDefaults() {
047: // Test if the Default-Values for the Screen, Layout and Navigation classes
048: assertEquals("Default Page failed",
049: TemplateService.DEFAULT_TEMPLATE_VALUE, ts
050: .getDefaultPage());
051: assertEquals("Default Screen failed",
052: TemplateService.DEFAULT_TEMPLATE_VALUE, ts
053: .getDefaultScreen());
054: assertEquals("Default Layout failed",
055: TemplateService.DEFAULT_TEMPLATE_VALUE, ts
056: .getDefaultLayout());
057: assertEquals("Default Navigation failed",
058: TemplateService.DEFAULT_TEMPLATE_VALUE, ts
059: .getDefaultNavigation());
060: }
061:
062: public void testVelocityDefaults() {
063: // Test if all the Velocity based Defaults for Page, Screen, Layout, Navigation
064: assertEquals("Default Page failed", "VelocityPage", ts
065: .getDefaultPageName("foo.vm"));
066: assertEquals("Default Screen failed", "VelocityScreen", ts
067: .getDefaultScreenName("foo.vm"));
068: assertEquals("Default Layout failed", "VelocityOnlyLayout", ts
069: .getDefaultLayoutName("foo.vm"));
070: assertEquals("Default Navigation failed", "VelocityNavigation",
071: ts.getDefaultNavigationName("foo.vm"));
072: }
073:
074: // Here comes the fun
075:
076: public void testNonExistingTemplate() throws Exception {
077: //
078: // Try a non existing Template. This should render with the default screen class,
079: // use the default Layout class and Navigation. It should be rendered with the
080: // default Layout Template but the Screen Template itself must not exist.
081: String templateName = "DoesNotExistPage.vm";
082: assertEquals("Screen translation failed", "VelocityScreen", ts
083: .getScreenName(templateName));
084: assertEquals("Layout translation failed", "VelocityOnlyLayout",
085: ts.getLayoutName(templateName));
086: assertEquals("Navigation translation failed",
087: "VelocityNavigation", ts
088: .getNavigationName(templateName));
089: }
090:
091: public void testNonExistingSublevelTemplate() throws Exception {
092: //
093: // Try a non existing Template in a sub-path. This should render with the default screen class,
094: // use the default Layout class and Navigation.
095: String templateName = "this,template,DoesNotExistPage.vm";
096: assertEquals("Screen translation failed", "VelocityScreen", ts
097: .getScreenName(templateName));
098: assertEquals("Layout translation failed", "VelocityOnlyLayout",
099: ts.getLayoutName(templateName));
100: assertEquals("Navigation translation failed",
101: "VelocityNavigation", ts
102: .getNavigationName(templateName));
103: }
104:
105: public void testExistingTemplate() throws Exception {
106: //
107: // Try an existing Template without any backing class. Should also return the default classes
108: String templateName = "ExistPage.vm";
109: assertEquals("Screen translation failed", "VelocityScreen", ts
110: .getScreenName(templateName));
111: assertEquals("Layout translation failed", "VelocityOnlyLayout",
112: ts.getLayoutName(templateName));
113: assertEquals("Navigation translation failed",
114: "VelocityNavigation", ts
115: .getNavigationName(templateName));
116: }
117:
118: public void testExistingSublevelTemplate() throws Exception {
119: //
120: // Try an existing Sublevel Template without any backing class. Should also return the default classes
121: String templateName = "existing,Page.vm";
122: assertEquals("Screen translation failed", "VelocityScreen", ts
123: .getScreenName(templateName));
124: assertEquals("Layout translation failed", "VelocityOnlyLayout",
125: ts.getLayoutName(templateName));
126: assertEquals("Navigation translation failed",
127: "VelocityNavigation", ts
128: .getNavigationName(templateName));
129: }
130:
131: // Now we start checking existing classes.
132:
133: public void testExistingClass() throws Exception {
134: //
135: // Now we have a class backed template. It has a separate Class for Screen, Navigation and
136: // Layout. It should find the matching class names in the screens, navigations and layout
137: // packages.
138: String templateName = "ExistPageWithClass.vm";
139: assertEquals("Screen translation failed", "ExistPageWithClass",
140: ts.getScreenName(templateName));
141: assertEquals("Layout translation failed", "ExistPageWithClass",
142: ts.getLayoutName(templateName));
143: assertEquals("Navigation translation failed",
144: "ExistPageWithClass", ts
145: .getNavigationName(templateName));
146: }
147:
148: public void testExistingSublevelClass() throws Exception {
149: //
150: // Now we have a class backed template. It has a separate Class for Screen, Navigation and
151: // Layout. It should find the matching class names in the screens, navigations and layout
152: // packages. For a twist, the classes are in a subpackage, so they should also find the
153: // classes in the sub packages.
154: String templateName = "existing,PageWithClass.vm";
155: assertEquals("Screen translation failed",
156: "existing.PageWithClass", ts
157: .getScreenName(templateName));
158: assertEquals("Layout translation failed",
159: "existing.PageWithClass", ts
160: .getLayoutName(templateName));
161: assertEquals("Navigation translation failed",
162: "existing.PageWithClass", ts
163: .getNavigationName(templateName));
164: }
165:
166: public void testDefaultClass() throws Exception {
167: //
168: // We look for a specific Template but it has no class. It has, however
169: // a Default class in its package. So the Loader should find the default
170: String templateName = "existing,dflt,PageWithClass.vm";
171: assertEquals("Screen translation failed",
172: "existing.dflt.Default", ts.getScreenName(templateName));
173: assertEquals("Layout translation failed",
174: "existing.dflt.Default", ts.getLayoutName(templateName));
175: assertEquals("Navigation translation failed",
176: "existing.dflt.Default", ts
177: .getNavigationName(templateName));
178: }
179:
180: public void testDefaultSublevelClass() throws Exception {
181: //
182: // We look for a specific Template but it has no class. It has, however
183: // a Default class in an upper package. So the Loader should find this.
184: String templateName = "existing,dflt,onelevel,twolevel,threelevel,PageWithClass.vm";
185: assertEquals("Screen translation failed",
186: "existing.dflt.Default", ts.getScreenName(templateName));
187: assertEquals("Layout translation failed",
188: "existing.dflt.Default", ts.getLayoutName(templateName));
189: assertEquals("Navigation translation failed",
190: "existing.dflt.Default", ts
191: .getNavigationName(templateName));
192: }
193:
194: public void testIgnoreExistingClass() throws Exception {
195: //
196: // This is a test, whether matching classes in upper level packages are ignored.
197: // We're looking for classes which don't exist. We have, however, matching names
198: // in an upper package. This should still match the Default classes, and not these.
199: String templateName = "sublevel,ExistPageWithClass.vm";
200: assertEquals("Screen translation failed", "VelocityScreen", ts
201: .getScreenName(templateName));
202: assertEquals("Layout translation failed", "VelocityOnlyLayout",
203: ts.getLayoutName(templateName));
204: assertEquals("Navigation translation failed",
205: "VelocityNavigation", ts
206: .getNavigationName(templateName));
207: }
208:
209: }
|