1   package org.apache.turbine;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  
21  import javax.servlet.ServletConfig;
22  import javax.servlet.ServletContext;
23  
24  import junit.framework.Test;
25  import junit.framework.TestSuite;
26  
27  import org.apache.turbine.Turbine;
28  import org.apache.turbine.test.BaseTestCase;
29  import org.apache.turbine.util.TurbineConfig;
30  import org.apache.turbine.util.TurbineXmlConfig;
31  
32  /***
33   * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
34   * servlet environment properly.
35   *
36   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
37   * @version $Id: TurbineConfigTest.java 264148 2005-08-29 14:21:04Z henning $
38   */
39  public class TurbineConfigTest
40      extends BaseTestCase
41  {
42      private static TurbineConfig tc = null;
43      private static TurbineXmlConfig txc = null;
44  
45      public TurbineConfigTest(String name)
46              throws Exception
47      {
48          super(name);
49      }
50  
51      public static Test suite()
52      {
53          return new TestSuite(TurbineConfigTest.class);
54      }
55  
56      public void testTurbineConfigWithPropertiesFile() throws Exception
57      {
58          String value = new File("/conf/test/TemplateService.properties").getPath();
59          tc = new TurbineConfig(".", value);
60  
61          ServletConfig config = (ServletConfig) tc;
62          ServletContext context = config.getServletContext();
63  
64          String confFile= Turbine.findInitParameter(context, config,
65                  TurbineConfig.PROPERTIES_PATH_KEY,
66                  null);
67          assertEquals(value, confFile);
68      }
69  
70      public void testTurbineXmlConfigWithConfigurationFile() throws Exception
71      {
72          String value = new File("/conf/test/TurbineConfiguration.xml").getPath();
73              txc = new TurbineXmlConfig(".", value);
74  
75          ServletConfig config = (ServletConfig) txc;
76          ServletContext context = config.getServletContext();
77  
78              String confFile= Turbine.findInitParameter(context, config,
79                      TurbineConfig.CONFIGURATION_PATH_KEY,
80                      null);
81          assertEquals(value, confFile);
82          }
83  }