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