001: package org.apache.turbine;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.commons.configuration.Configuration;
026:
027: import org.apache.turbine.test.BaseTestCase;
028: import org.apache.turbine.util.TurbineConfig;
029: import org.apache.turbine.util.TurbineXmlConfig;
030:
031: /**
032: * Tests that the ConfigurationFactory and regular old properties methods both work.
033: * Verify the overriding of properties.
034: *
035: * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
036: * @version $Id: ConfigurationTest.java 534527 2007-05-02 16:10:59Z tv $
037: */
038: public class ConfigurationTest extends BaseTestCase {
039: public static final String SERVICE_PREFIX = "services.";
040:
041: /**
042: * A <code>Service</code> property determining its implementing
043: * class name .
044: */
045: public static final String CLASSNAME_SUFFIX = ".classname";
046:
047: private static TurbineConfig tc = null;
048: private static TurbineXmlConfig txc = null;
049:
050: public ConfigurationTest(String name) throws Exception {
051: super (name);
052: }
053:
054: public static Test suite() {
055: return new TestSuite(ConfigurationTest.class);
056: }
057:
058: public void testCreateTurbineWithConfigurationXML()
059: throws Exception {
060: txc = new TurbineXmlConfig(".",
061: "/conf/test/TurbineConfiguration.xml");
062:
063: try {
064: txc.initialize();
065:
066: Configuration configuration = Turbine.getConfiguration();
067: assertNotNull("No Configuration Object found!",
068: configuration);
069: assertFalse("Make sure we have values", configuration
070: .isEmpty());
071:
072: // overridden value
073: String key = "module.cache";
074:
075: assertEquals("Read a config value " + key + ", received:"
076: + configuration.getString(key), "true",
077: configuration.getString(key));
078:
079: // non overridden value
080: key = "scheduledjob.cache.size";
081: assertEquals("Read a config value " + key + ", received:"
082: + configuration.getString(key), "10", configuration
083: .getString(key));
084: } catch (Exception e) {
085: throw e;
086: } finally {
087: txc.dispose();
088: }
089: }
090:
091: public void testCreateTurbineWithConfiguration() throws Exception {
092: tc = new TurbineConfig(".",
093: "/conf/test/TemplateService.properties");
094:
095: try {
096: tc.initialize();
097:
098: Configuration configuration = Turbine.getConfiguration();
099: assertNotNull("No Configuration Object found!",
100: configuration);
101: assertFalse("Make sure we have values", configuration
102: .isEmpty());
103:
104: String key = "scheduledjob.cache.size";
105: assertEquals("Read a config value " + key + ", received:"
106: + configuration.getString(key), "10", configuration
107: .getString(key));
108: } catch (Exception e) {
109: throw e;
110: } finally {
111: tc.dispose();
112: }
113: }
114:
115: }
|