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