001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.locator;
018:
019: import java.util.ArrayList;
020:
021: import junit.framework.Test;
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024:
025: /**
026: * TestTemplateLocator
027: *
028: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
029: * @version $Id: TestTemplateLocator.java 516448 2007-03-09 16:25:47Z ate $
030: */
031: public class TestTemplateLocator extends TestCase {
032: private JetspeedTemplateLocator templateLocator;
033:
034: public TestTemplateLocator(String name) {
035: super (name);
036: }
037:
038: /**
039: * Start the tests.
040: *
041: * @param args the arguments. Not used
042: */
043: public static void main(String args[]) {
044: junit.awtui.TestRunner
045: .main(new String[] { TestTemplateLocator.class
046: .getName() });
047: }
048:
049: public static Test suite() {
050: // All methods starting with "test" will be executed in the test suite.
051: return new TestSuite(TestTemplateLocator.class);
052: }
053:
054: public void testLocateTemplate() throws Exception {
055: // TemplateLocator component = (TemplateLocator)componentManager.getComponent("TemplateLocator");
056: assertNotNull("template service is null", templateLocator);
057: LocatorDescriptor locator = templateLocator
058: .createLocatorDescriptor("email");
059: locator.setName("test.vm");
060: TemplateDescriptor template = templateLocator
061: .locateTemplate(locator);
062: assertNotNull("template is null", template);
063: System.out.println("template1 = " + template);
064: assertTrue("template1 result", "type/email/name/test.vm"
065: .endsWith(template.toString()));
066:
067: LocatorDescriptor locator2 = templateLocator
068: .createLocatorDescriptor("email");
069: locator2.setName("htmltest.vm");
070: locator2.setMediaType("html");
071: template = templateLocator.locateTemplate(locator2);
072: assertNotNull("template is null", template);
073: System.out.println("template2 = " + template);
074: assertTrue("template2 result",
075: "type/email/media-type/html/name/htmltest.vm"
076: .endsWith(template.toString()));
077:
078: LocatorDescriptor locator3 = templateLocator
079: .createLocatorDescriptor("email");
080: locator3.setName("entest.vm");
081: locator3.setMediaType("html");
082: locator3.setLanguage("en");
083: template = templateLocator.locateTemplate(locator3);
084: assertNotNull("template is null", template);
085: System.out.println("template3 = " + template);
086: assertTrue("template3 result",
087: "type/email/media-type/html/language/en/name/entest.vm"
088: .endsWith(template.toString()));
089:
090: LocatorDescriptor locator4 = templateLocator
091: .createLocatorDescriptor("email");
092: locator4.setName("ustest.vm");
093: locator4.setMediaType("html");
094: locator4.setLanguage("en");
095: locator4.setCountry("US");
096: template = templateLocator.locateTemplate(locator4);
097: assertNotNull("template is null", template);
098: System.out.println("template4 = " + template);
099: assertTrue("template4 result",
100: "type/email/media-type/html/language/en/country/US/name/ustest.vm"
101: .endsWith(template.toString()));
102:
103: // test fallback
104: LocatorDescriptor locator5 = templateLocator
105: .createLocatorDescriptor("email");
106: locator5.setName("entest.vm");
107: locator5.setMediaType("html");
108: locator5.setLanguage("en");
109: locator5.setCountry("UZ");
110: template = templateLocator.locateTemplate(locator5);
111: assertNotNull("template is null", template);
112: System.out.println("template5 = " + template);
113: assertTrue("template5 result",
114: "type/email/media-type/html/language/en/name/entest.vm"
115: .endsWith(template.toString()));
116:
117: // test fallback all the way to email
118: LocatorDescriptor locator6 = templateLocator
119: .createLocatorDescriptor("email");
120: locator6.setName("test.vm");
121: locator6.setMediaType("html");
122: locator6.setLanguage("en");
123: locator6.setCountry("UZ");
124: template = templateLocator.locateTemplate(locator6);
125: System.out.println("template6 = " + template);
126: assertTrue("template6 result", "type/email/name/test.vm"
127: .endsWith(template.toString()));
128:
129: }
130:
131: /* (non-Javadoc)
132: * @see junit.framework.TestCase#setUp()
133: */
134: protected void setUp() throws Exception {
135: ArrayList roots = new ArrayList(1);
136: roots.add("./testdata/templates");
137: ArrayList classes = new ArrayList(2);
138: classes.add(JetspeedTemplateDescriptor.class);
139: classes.add(JetspeedLocatorDescriptor.class);
140:
141: templateLocator = new JetspeedTemplateLocator(roots, classes,
142: "email", "./");
143: templateLocator.start();
144: }
145: }
|