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 all the various template mappings for Screen and Layout
030: * templates of the template service.
031: *
032: * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
033: * @version $Id: TemplateTest.java 534527 2007-05-02 16:10:59Z tv $
034: */
035:
036: public class TemplateTest extends BaseTurbineTest {
037: private static TemplateService ts = null;
038:
039: public TemplateTest(String name) throws Exception {
040: super (name, "/conf/test/TemplateService.properties");
041:
042: ts = (TemplateService) TurbineServices.getInstance()
043: .getService(TemplateService.SERVICE_NAME);
044: }
045:
046: public static Test suite() {
047: return new TestSuite(TemplateTest.class);
048: }
049:
050: public void testTemplateDefaults() {
051: assertEquals("Default LayoutTemplate failed",
052: TemplateService.DEFAULT_TEMPLATE_VALUE, ts
053: .getDefaultLayoutTemplate());
054: }
055:
056: public void testVelocityDefaults() {
057: assertEquals("Default LayoutTemplate failed", "Default.vm", ts
058: .getDefaultLayoutTemplateName("foo.vm"));
059: }
060:
061: public void testNonExistingTemplate() throws Exception {
062: //
063: // Try a non existing Template. This should render with the default screen class,
064: // use the default Layout class and Navigation. It should be rendered with the
065: // default Layout Template but the Screen Template itself must not exist.
066: String templateName = "DoesNotExistPage.vm";
067: assertEquals("LayoutTemplate translation failed", "Default.vm",
068: ts.getLayoutTemplateName(templateName));
069: assertEquals("ScreenTemplate translation failed", null, ts
070: .getScreenTemplateName(templateName));
071: }
072:
073: public void testNonExistingSublevelTemplate() throws Exception {
074: //
075: // Try a non existing Template in a sub-path. This should render with the default screen class,
076: // use the default Layout class and Navigation. It should be rendered with the
077: // default Layout Template but the Screen Template itself must not exist.
078: String templateName = "this,template,DoesNotExistPage.vm";
079: assertEquals("LayoutTemplate translation failed", "Default.vm",
080: ts.getLayoutTemplateName(templateName));
081: assertEquals("ScreenTemplate translation failed", null, ts
082: .getScreenTemplateName(templateName));
083: }
084:
085: public void testExistingTemplate() throws Exception {
086: //
087: // Try an existing Template. As we already know, missing classes are found correctly
088: // so we test only Layout and Screen template. This should return the "Default" Layout
089: // template to render and the Screen Template for the Page to render
090: String templateName = "ExistPage.vm";
091: assertEquals("LayoutTemplate translation failed", "Default.vm",
092: ts.getLayoutTemplateName(templateName));
093: assertEquals("ScreenTemplate translation failed",
094: "ExistPage.vm", ts.getScreenTemplateName(templateName));
095: }
096:
097: public void testExistingSublevelTemplate() throws Exception {
098: //
099: // Try an existing Template. As we already know, missing classes are found correctly
100: // so we test only Layout and Screen template. This should return the "Default" Layout
101: // template to render and the Screen Template for the Page to render. The names returned
102: // by the template service are "/" separated so that e.g. Velocity can use this.
103: String templateName = "existing,Page.vm";
104: assertEquals("LayoutTemplate translation failed", "Default.vm",
105: ts.getLayoutTemplateName(templateName));
106: assertEquals("ScreenTemplate translation failed",
107: "existing/Page.vm", ts
108: .getScreenTemplateName(templateName));
109: }
110:
111: public void testExistingLayoutTemplate() throws Exception {
112: //
113: // Try an existing Template. This time we have a backing Layout page. So the getLayoutTemplateName
114: // method should not return the Default but our Layout page.
115: //
116: String templateName = "ExistPageWithLayout.vm";
117: assertEquals("LayoutTemplate translation failed",
118: "ExistPageWithLayout.vm", ts
119: .getLayoutTemplateName(templateName));
120: assertEquals("ScreenTemplate translation failed",
121: "ExistPageWithLayout.vm", ts
122: .getScreenTemplateName(templateName));
123: }
124:
125: public void testExistingSublevelLayoutTemplate() throws Exception {
126: //
127: // Try an existing Template. This time we have a backing Layout page. So the getLayoutTemplateName
128: // method should not return the Default but our Layout page.
129: //
130: String templateName = "existing,ExistSublevelPageWithLayout.vm";
131: assertEquals("LayoutTemplate translation failed",
132: "existing/ExistSublevelPageWithLayout.vm", ts
133: .getLayoutTemplateName(templateName));
134: assertEquals("ScreenTemplate translation failed",
135: "existing/ExistSublevelPageWithLayout.vm", ts
136: .getScreenTemplateName(templateName));
137: }
138:
139: public void testExistingDefaultLayoutTemplate() throws Exception {
140: //
141: // Try an existing Template in a sublevel. This has an equally named Layout in the root. This
142: // test must find the Template itself but the "Default" layout
143: //
144: String templateName = "existing,ExistPageWithLayout.vm";
145: assertEquals("LayoutTemplate translation failed", "Default.vm",
146: ts.getLayoutTemplateName(templateName));
147: assertEquals("ScreenTemplate translation failed",
148: "existing/ExistPageWithLayout.vm", ts
149: .getScreenTemplateName(templateName));
150: }
151: }
|