001 package org.apache.turbine.services.velocity; 002 003 004 /* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024 import org.apache.commons.collections.ExtendedProperties; 025 import org.apache.commons.configuration.Configuration; 026 import org.apache.turbine.Turbine; 027 import org.apache.turbine.services.TurbineServices; 028 import org.apache.turbine.test.BaseTestCase; 029 import org.apache.turbine.util.TurbineConfig; 030 031 /** 032 * Tests startup of the Velocity Service and translation of various 033 * path patterns. 034 * 035 * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a> 036 * @version $Id: PathConverterTest.java 615328 2008-01-25 20:25:05Z tv $ 037 */ 038 039 public class PathConverterTest 040 extends BaseTestCase 041 { 042 private static TurbineConfig tc = null; 043 private static VelocityService vs = null; 044 private static String fileSeperator = System.getProperty("file.separator"); 045 046 public PathConverterTest(String name) 047 throws Exception 048 { 049 super(name); 050 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties"); 051 tc.initialize(); 052 053 vs = (VelocityService) TurbineServices.getInstance().getService(VelocityService.SERVICE_NAME); 054 } 055 056 057 public void testService() 058 throws Exception 059 { 060 061 // Can we start the service? 062 assertNotNull("Could not load Service!", vs); 063 } 064 065 public void testPathTranslation() 066 throws Exception 067 { 068 Configuration conf = vs.getConfiguration(); 069 ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf); 070 071 String rootPath = Turbine.getRealPath(""); 072 073 String [] test1 = ep.getStringArray("test1.resource.loader.path"); 074 assertEquals("No Test1 Property found", 1, test1.length); 075 assertEquals("Test1 Path translation failed", rootPath 076 +fileSeperator+"relative"+fileSeperator+"path" , test1[0]); 077 078 String [] test2 = ep.getStringArray("test2.resource.loader.path"); 079 assertEquals("No Test2 Property found", 1, test2.length); 080 assertEquals("Test2 Path translation failed", rootPath 081 +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]); 082 083 String [] test3 = ep.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.getStringArray("test4.resource.loader.path"); 089 assertEquals("No Test4 Property found", 1, test4.length); 090 assertEquals("Test4 Path translation failed", rootPath 091 +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]); 092 093 String [] test5 = ep.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.getStringArray("test6.resource.loader.path"); 099 assertEquals("No Test6 Property found", 1, test6.length); 100 assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]); 101 102 String [] test7 = ep.getStringArray("test7.resource.loader.path"); 103 assertEquals("No Test7 Property found", 1, test7.length); 104 assertEquals("Test7 Path translation failed", rootPath 105 +fileSeperator+"file"+fileSeperator 106 +"system"+fileSeperator+"reference" , test7[0]); 107 108 String [] test8 = ep.getStringArray("test8.resource.loader.path"); 109 assertEquals("No Test8 Property found", 1, test8.length); 110 assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]); 111 112 } 113 }