001: package org.apache.turbine.services.velocity;
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.commons.collections.ExtendedProperties;
023: import org.apache.commons.configuration.Configuration;
024:
025: import org.apache.turbine.Turbine;
026: import org.apache.turbine.services.TurbineServices;
027: import org.apache.turbine.test.BaseTurbineTest;
028:
029: /**
030: * Tests startup of the Velocity Service and translation of various
031: * path patterns.
032: *
033: * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
034: * @version $Id: PathConverterTest.java 264148 2005-08-29 14:21:04Z henning $
035: */
036: public class PathConverterTest extends BaseTurbineTest {
037: private static VelocityService vs = null;
038: private static String fileSeperator = System
039: .getProperty("file.separator");
040:
041: public PathConverterTest(String name) throws Exception {
042: super (name, "/conf/test/TemplateService.properties");
043:
044: vs = (VelocityService) TurbineServices.getInstance()
045: .getService(VelocityService.SERVICE_NAME);
046: }
047:
048: public static Test suite() {
049: return new TestSuite(PathConverterTest.class);
050: }
051:
052: public void testService() throws Exception {
053:
054: // Can we start the service?
055: assertNotNull("Could not load Service!", vs);
056: }
057:
058: public void testPathTranslation() throws Exception {
059: Configuration conf = vs.getConfiguration();
060: ExtendedProperties ep = ((TurbineVelocityService) vs)
061: .createVelocityProperties(conf);
062:
063: String rootPath = Turbine.getRealPath("");
064:
065: String[] test1 = ep
066: .getStringArray("test1.resource.loader.path");
067: assertEquals("No Test1 Property found", 1, test1.length);
068: assertEquals("Test1 Path translation failed", rootPath
069: + fileSeperator + "relative" + fileSeperator + "path",
070: test1[0]);
071:
072: String[] test2 = ep
073: .getStringArray("test2.resource.loader.path");
074: assertEquals("No Test2 Property found", 1, test2.length);
075: assertEquals("Test2 Path translation failed", rootPath
076: + fileSeperator + "absolute" + fileSeperator + "path",
077: test2[0]);
078:
079: String[] test3 = ep
080: .getStringArray("test3.resource.loader.path");
081: assertEquals("No Test3 Property found", 1, test2.length);
082: assertEquals("Test3 Path translation failed", rootPath
083: + fileSeperator + "jar-file.jar!/", test3[0]);
084:
085: String[] test4 = ep
086: .getStringArray("test4.resource.loader.path");
087: assertEquals("No Test4 Property found", 1, test4.length);
088: assertEquals("Test4 Path translation failed", rootPath
089: + fileSeperator + "jar-file.jar!/with/some/extensions",
090: test4[0]);
091:
092: String[] test5 = ep
093: .getStringArray("test5.resource.loader.path");
094: assertEquals("No Test5 Property found", 1, test5.length);
095: assertEquals("Test5 Path translation failed", rootPath
096: + fileSeperator + "jar-file.jar", test5[0]);
097:
098: String[] test6 = ep
099: .getStringArray("test6.resource.loader.path");
100: assertEquals("No Test6 Property found", 1, test6.length);
101: assertEquals("Test6 Path translation failed",
102: "jar:http://jar.on.website/", test6[0]);
103:
104: String[] test7 = ep
105: .getStringArray("test7.resource.loader.path");
106: assertEquals("No Test7 Property found", 1, test7.length);
107: assertEquals("Test7 Path translation failed", rootPath
108: + fileSeperator + "file" + fileSeperator + "system"
109: + fileSeperator + "reference", test7[0]);
110:
111: String[] test8 = ep
112: .getStringArray("test8.resource.loader.path");
113: assertEquals("No Test8 Property found", 1, test8.length);
114: assertEquals("Test8 Path translation failed",
115: "http://reference.on.website/", test8[0]);
116:
117: }
118: }
|