1   package org.apache.turbine;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  import org.apache.commons.configuration.Configuration;
25  import org.apache.turbine.test.BaseTestCase;
26  import org.apache.turbine.util.TurbineConfig;
27  import org.apache.turbine.util.TurbineXmlConfig;
28  
29  /**
30   * Tests that the ConfigurationFactory and regular old properties methods both work.
31   * Verify the overriding of properties.
32   *
33   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
34   * @version $Id: ConfigurationTest.java 615328 2008-01-25 20:25:05Z tv $
35   */
36  public class ConfigurationTest extends BaseTestCase
37  {
38      public static final String SERVICE_PREFIX = "services.";
39  
40      /**
41       * A <code>Service</code> property determining its implementing
42       * class name .
43       */
44      public static final String CLASSNAME_SUFFIX = ".classname";
45  
46      private static TurbineConfig tc = null;
47      private static TurbineXmlConfig txc = null;
48  
49      public ConfigurationTest(String name) throws Exception
50      {
51          super(name);
52      }
53  
54      public void testCreateTurbineWithConfigurationXML() throws Exception
55      {
56          txc = new TurbineXmlConfig(".", "/conf/test/TurbineConfiguration.xml");
57  
58          try
59          {
60              txc.initialize();
61  
62              Configuration configuration = Turbine.getConfiguration();
63              assertNotNull("No Configuration Object found!", configuration);
64              assertFalse("Make sure we have values", configuration.isEmpty());
65  
66              // overridden value
67              String key = "module.cache";
68              assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "true", configuration.getString(key));
69  
70              // non overridden value
71              key = "scheduledjob.cache.size";
72              assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
73          }
74          catch (Exception e)
75          {
76              throw e;
77          }
78          finally
79          {
80              txc.dispose();
81          }
82      }
83  
84      public void testCreateTurbineWithConfiguration() throws Exception
85      {
86          tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
87  
88          try
89          {
90              tc.initialize();
91  
92              Configuration configuration = Turbine.getConfiguration();
93              assertNotNull("No Configuration Object found!", configuration);
94              assertFalse("Make sure we have values", configuration.isEmpty());
95  
96              String key = "scheduledjob.cache.size";
97              assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key));
98          }
99          catch (Exception e)
100         {
101             throw e;
102         }
103         finally
104         {
105             tc.dispose();
106         }
107     }
108 
109 }