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