1   package org.apache.turbine;
2   
3   /*
4    * Copyright 2001-2004 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.util.List;
20  
21  import junit.framework.Test;
22  import junit.framework.TestSuite;
23  
24  import org.apache.commons.configuration.Configuration;
25  
26  import org.apache.turbine.test.BaseTestCase;
27  import org.apache.turbine.util.TurbineConfig;
28  import org.apache.turbine.util.TurbineXmlConfig;
29  
30  /***
31   * Tests that the ConfigurationFactory and regular old properties methods both work.
32   * Verify the overriding of properties.
33   * 
34   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
35   * @version $Id: ConfigurationTest.java,v 1.9.2.3 2004/08/16 22:57:51 henning Exp $
36   */
37  public class ConfigurationTest extends BaseTestCase
38  {
39      public static final String SERVICE_PREFIX = "services.";
40  
41      /***
42       * A <code>Service</code> property determining its implementing
43       * class name .
44       */
45      public static final String CLASSNAME_SUFFIX = ".classname";
46  
47      private static TurbineConfig tc = null;
48      private static TurbineXmlConfig txc = null;
49  
50      public ConfigurationTest(String name) throws Exception
51      {
52          super(name);
53      }
54  
55      public static Test suite()
56      {
57          return new TestSuite(ConfigurationTest.class);
58      }
59  
60      public void testCreateTurbineWithConfigurationXML() throws Exception
61      {
62          txc = new TurbineXmlConfig(".", "/conf/test/TurbineConfiguration.xml");
63  
64          try
65          {
66              txc.initialize();
67  
68              Configuration configuration = Turbine.getConfiguration();
69              assertNotNull("No Configuration Object found!", configuration);
70              assertFalse("Make sure we have values", configuration.isEmpty());
71  
72              // overridden value
73              String key = "module.cache";
74              
75              assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "true", configuration.getString(key));
76  
77              // non overridden value
78              key = "scheduledjob.cache.size";
79              assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
80          }
81          catch (Exception e)
82          {
83              throw e;
84          }
85          finally
86          {
87              txc.dispose();
88          }
89      }
90  
91      public void testCreateTurbineWithConfiguration() throws Exception
92      {
93          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
94  
95          try
96          {
97              tc.initialize();
98  
99              Configuration configuration = Turbine.getConfiguration();
100             assertNotNull("No Configuration Object found!", configuration);
101             assertFalse("Make sure we have values", configuration.isEmpty());
102 
103             String key = "scheduledjob.cache.size";
104             assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
105         }
106         catch (Exception e)
107         {
108             throw e;
109         }
110         finally
111         {
112             tc.dispose();
113         }
114     }
115 
116 }