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