View Javadoc

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