View Javadoc

    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 static org.junit.Assert.assertEquals;
    25  import static org.junit.Assert.assertNotNull;
    26
    27  import org.apache.commons.collections.ExtendedProperties;
    28  import org.apache.commons.configuration.Configuration;
    29  import org.apache.turbine.Turbine;
    30  import org.apache.turbine.services.TurbineServices;
    31  import org.apache.turbine.test.BaseTestCase;
    32  import org.apache.turbine.util.TurbineConfig;
    33  import org.junit.AfterClass;
    34  import org.junit.BeforeClass;
    35  import org.junit.Test;
    36
    37  /**
    38   * Tests startup of the Velocity Service and translation of various
    39   * path patterns.
    40   *
    41   * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
    42   * @version $Id: PathConverterTest.java 1812628 2017-10-19 12:34:25Z gk $
    43   */
    44
    45  public class PathConverterTest
    46      extends BaseTestCase
    47  {
    48      private static TurbineConfig tc = null;
    49      private static VelocityService vs = null;
    50      private static String fileSeperator = System.getProperty("file.separator");
    51
    52
    53      @BeforeClass
    54      public static void setUp() throws Exception {
    55          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
    56          tc.initialize();
    57
    58          vs = (VelocityService) TurbineServices.getInstance().getService(VelocityService.SERVICE_NAME);
    59      }
    60
    61      @AfterClass
    62      public static void destroy() throws Exception {
    63          vs.shutdown();
    64          tc.dispose();
    65      }
    66
    67      @Test public void testService()
    68          throws Exception
    69      {
    70
    71          // Can we start the service?
    72          assertNotNull("Could not load Service!", vs);
    73      }
    74
    75      @Test
    76      public void testPathTranslation()
    77          throws Exception
    78      {
    79          Configuration conf = vs.getConfiguration();
    80          ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
    81
    82          String rootPath = Turbine.getRealPath("");
    83
    84          String [] test1 = ep.getStringArray("test1.resource.loader.path");
    85          assertEquals("No Test1 Property found", 1, test1.length);
    86          assertEquals("Test1 Path translation failed", rootPath
    87                  +fileSeperator+"relative"+fileSeperator+"path" , test1[0]);
    88
    89          String [] test2 = ep.getStringArray("test2.resource.loader.path");
    90          assertEquals("No Test2 Property found", 1, test2.length);
    91          assertEquals("Test2 Path translation failed", rootPath
    92                  +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]);
    93
    94          String [] test3 = ep.getStringArray("test3.resource.loader.path");
    95          assertEquals("No Test3 Property found", 1, test2.length);
    96          assertEquals("Test3 Path translation failed", rootPath
    97                  +fileSeperator+"jar-file.jar!/", test3[0]);
    98
    99          String [] test4 = ep.getStringArray("test4.resource.loader.path");
    100         assertEquals("No Test4 Property found", 1, test4.length);
    101         assertEquals("Test4 Path translation failed", rootPath
    102                 +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]);
    103
    104         String [] test5 = ep.getStringArray("test5.resource.loader.path");
    105         assertEquals("No Test5 Property found", 1, test5.length);
    106         assertEquals("Test5 Path translation failed", rootPath
    107                 +fileSeperator+"jar-file.jar" , test5[0]);
    108
    109         String [] test6 = ep.getStringArray("test6.resource.loader.path");
    110         assertEquals("No Test6 Property found", 1, test6.length);
    111         assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]);
    112
    113         String [] test7 = ep.getStringArray("test7.resource.loader.path");
    114         assertEquals("No Test7 Property found", 1, test7.length);
    115         assertEquals("Test7 Path translation failed", rootPath
    116                 +fileSeperator+"file"+fileSeperator
    117                 +"system"+fileSeperator+"reference" , test7[0]);
    118
    119         String [] test8 = ep.getStringArray("test8.resource.loader.path");
    120         assertEquals("No Test8 Property found", 1, test8.length);
    121         assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]);
    122
    123     }
    124 }