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  
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  
33  /**
34   * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
35   * servlet environment properly.
36   *
37   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
38   * @version $Id: TurbineConfigTest.java 615328 2008-01-25 20:25:05Z tv $
39   */
40  public class TurbineConfigTest
41      extends BaseTestCase
42  {
43      private static TurbineConfig tc = null;
44      private static TurbineXmlConfig txc = null;
45  
46      public TurbineConfigTest(String name)
47              throws Exception
48      {
49          super(name);
50      }
51  
52      public void testTurbineConfigWithPropertiesFile() throws Exception
53      {
54          String value = new File("/conf/test/TemplateService.properties").getPath();
55          tc = new TurbineConfig(".", value);
56  
57          ServletConfig config = (ServletConfig) tc;
58          ServletContext context = config.getServletContext();
59  
60          String confFile= Turbine.findInitParameter(context, config,
61                  TurbineConfig.PROPERTIES_PATH_KEY,
62                  null);
63          assertEquals(value, confFile);
64      }
65  
66      public void testTurbineXmlConfigWithConfigurationFile() throws Exception
67      {
68          String value = new File("/conf/test/TurbineConfiguration.xml").getPath();
69              txc = new TurbineXmlConfig(".", value);
70  
71          ServletConfig config = (ServletConfig) txc;
72          ServletContext context = config.getServletContext();
73  
74              String confFile= Turbine.findInitParameter(context, config,
75                      TurbineConfig.CONFIGURATION_PATH_KEY,
76                      null);
77          assertEquals(value, confFile);
78          }
79  }