View Javadoc

    1   package org.apache.turbine;
    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 static org.junit.Assert.assertEquals;
    23
    24  import java.io.File;
    25
    26  import javax.servlet.ServletConfig;
    27  import javax.servlet.ServletContext;
    28
    29  import org.apache.turbine.test.BaseTestCase;
    30  import org.apache.turbine.util.TurbineConfig;
    31  import org.apache.turbine.util.TurbineXmlConfig;
    32  import org.junit.Test;
    33
    34  /**
    35   * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
    36   * servlet environment properly.
    37   *
    38   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    39   * @version $Id: TurbineConfigTest.java 1724804 2016-01-15 13:44:43Z tv $
    40   */
    41  public class TurbineConfigTest extends BaseTestCase
    42  {
    43      @Test
    44      public void testTurbineConfigWithPropertiesFile() throws Exception
    45      {
    46          String value = new File("/conf/test/TemplateService.properties").getPath();
    47          TurbineConfig tc = new TurbineConfig(".", value);
    48          Turbine turbine = new Turbine();
    49
    50          ServletConfig config = tc;
    51          ServletContext context = config.getServletContext();
    52
    53          String confFile = turbine.findInitParameter(context, config, TurbineConfig.PROPERTIES_PATH_KEY, null);
    54          assertEquals(value, confFile);
    55      }
    56
    57      @Test
    58      public void testTurbineXmlConfigWithConfigurationFile() throws Exception
    59      {
    60          String value = new File("/conf/test/TurbineConfiguration.xml").getPath();
    61          TurbineXmlConfig txc = new TurbineXmlConfig(".", value);
    62          Turbine turbine = new Turbine();
    63
    64          ServletConfig config = txc;
    65          ServletContext context = config.getServletContext();
    66
    67          String confFile = turbine.findInitParameter(context, config, TurbineConfig.CONFIGURATION_PATH_KEY, null);
    68          assertEquals(value, confFile);
    69      }
    70  }