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 java.io.File;
23  
24  import javax.servlet.ServletConfig;
25  import javax.servlet.ServletContext;
26  
27  import junit.framework.Test;
28  import junit.framework.TestSuite;
29  
30  import org.apache.turbine.Turbine;
31  import org.apache.turbine.test.BaseTestCase;
32  import org.apache.turbine.util.TurbineConfig;
33  import org.apache.turbine.util.TurbineXmlConfig;
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 534527 2007-05-02 16:10:59Z tv $
41   */
42  public class TurbineConfigTest
43      extends BaseTestCase
44  {
45      private static TurbineConfig tc = null;
46      private static TurbineXmlConfig txc = null;
47  
48      public TurbineConfigTest(String name)
49              throws Exception
50      {
51          super(name);
52      }
53  
54      public static Test suite()
55      {
56          return new TestSuite(TurbineConfigTest.class);
57      }
58  
59      public void testTurbineConfigWithPropertiesFile() throws Exception
60      {
61          String value = new File("/conf/test/TemplateService.properties").getPath();
62          tc = new TurbineConfig(".", value);
63  
64          ServletConfig config = (ServletConfig) tc;
65          ServletContext context = config.getServletContext();
66  
67          String confFile= Turbine.findInitParameter(context, config,
68                  TurbineConfig.PROPERTIES_PATH_KEY,
69                  null);
70          assertEquals(value, confFile);
71      }
72  
73      public void testTurbineXmlConfigWithConfigurationFile() throws Exception
74      {
75          String value = new File("/conf/test/TurbineConfiguration.xml").getPath();
76              txc = new TurbineXmlConfig(".", value);
77  
78          ServletConfig config = (ServletConfig) txc;
79          ServletContext context = config.getServletContext();
80  
81              String confFile= Turbine.findInitParameter(context, config,
82                      TurbineConfig.CONFIGURATION_PATH_KEY,
83                      null);
84          assertEquals(value, confFile);
85          }
86  }