1   package org.apache.turbine.services.velocity;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.Test;
23  import junit.framework.TestSuite;
24  
25  import org.apache.commons.collections.ExtendedProperties;
26  import org.apache.commons.configuration.Configuration;
27  
28  import org.apache.turbine.Turbine;
29  import org.apache.turbine.services.TurbineServices;
30  import org.apache.turbine.test.BaseTurbineTest;
31  
32  /***
33   * Tests startup of the Velocity Service and translation of various
34   * path patterns.
35   *
36   * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
37   * @version $Id: PathConverterTest.java 534527 2007-05-02 16:10:59Z tv $
38   */
39  public class PathConverterTest
40      extends BaseTurbineTest
41  {
42      private static VelocityService vs = null;
43      private static String fileSeperator = System.getProperty("file.separator");
44  
45      public PathConverterTest(String name)
46              throws Exception
47      {
48          super(name, "/conf/test/TemplateService.properties");
49  
50          vs = (VelocityService) TurbineServices.getInstance().getService(VelocityService.SERVICE_NAME);
51      }
52  
53      public static Test suite()
54      {
55          return new TestSuite(PathConverterTest.class);
56      }
57  
58      public void testService()
59          throws Exception
60      {
61  
62          // Can we start the service?
63          assertNotNull("Could not load Service!", vs);
64      }
65  
66      public void testPathTranslation()
67          throws Exception
68      {
69          Configuration conf = vs.getConfiguration();
70          ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
71  
72          String rootPath = Turbine.getRealPath("");
73  
74          String [] test1 = ep.getStringArray("test1.resource.loader.path");
75          assertEquals("No Test1 Property found", 1, test1.length);
76          assertEquals("Test1 Path translation failed", rootPath
77                  +fileSeperator+"relative"+fileSeperator+"path" , test1[0]);
78  
79          String [] test2 = ep.getStringArray("test2.resource.loader.path");
80          assertEquals("No Test2 Property found", 1, test2.length);
81          assertEquals("Test2 Path translation failed", rootPath
82                  +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]);
83  
84          String [] test3 = ep.getStringArray("test3.resource.loader.path");
85          assertEquals("No Test3 Property found", 1, test2.length);
86          assertEquals("Test3 Path translation failed", rootPath
87                  +fileSeperator+"jar-file.jar!/", test3[0]);
88  
89          String [] test4 = ep.getStringArray("test4.resource.loader.path");
90          assertEquals("No Test4 Property found", 1, test4.length);
91          assertEquals("Test4 Path translation failed", rootPath
92                  +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]);
93  
94          String [] test5 = ep.getStringArray("test5.resource.loader.path");
95          assertEquals("No Test5 Property found", 1, test5.length);
96          assertEquals("Test5 Path translation failed", rootPath
97                  +fileSeperator+"jar-file.jar" , test5[0]);
98  
99          String [] test6 = ep.getStringArray("test6.resource.loader.path");
100         assertEquals("No Test6 Property found", 1, test6.length);
101         assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]);
102 
103         String [] test7 = ep.getStringArray("test7.resource.loader.path");
104         assertEquals("No Test7 Property found", 1, test7.length);
105         assertEquals("Test7 Path translation failed", rootPath
106                 +fileSeperator+"file"+fileSeperator
107                 +"system"+fileSeperator+"reference" , test7[0]);
108 
109         String [] test8 = ep.getStringArray("test8.resource.loader.path");
110         assertEquals("No Test8 Property found", 1, test8.length);
111         assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]);
112 
113     }
114 }