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