epugh 2003/02/28 12:24:12
Added: configuration/src/test/org/apache/commons/configuration
TestCompositeConfiguration.java
TestDOM4JConfiguration.java
Log:
New Configuration types, JNDI and Composite! supporting tests
Revision Changes Path
1.1
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
Index: TestCompositeConfiguration.java
===================================================================
package org.apache.commons.configuration;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import junit.framework.TestCase;
/**
* test loading multiple configurations
*
* @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
* @version $Id: TestCompositeConfiguration.java,v 1.1 2003/02/28 20:24:12 epugh Exp
$
*/
public class TestCompositeConfiguration extends TestCase {
protected BasePropertiesConfiguration conf1;
protected BasePropertiesConfiguration conf2;
protected DOM4JConfiguration dom4jConf;
protected CompositeConfiguration cc;
/** The File that we test with */
private String testProperties =
new File("conf/test.properties").getAbsolutePath();
private String testProperties2 =
new File("conf/test2.properties").getAbsolutePath();
private String testPropertiesXML =
new File("conf/test.xml").getAbsolutePath();
public TestCompositeConfiguration(String s) {
super(s);
}
protected void setUp() throws Exception {
cc = new CompositeConfiguration();
conf1 = new PropertiesConfiguration(testProperties);
conf2 = new PropertiesConfiguration(testProperties2);
dom4jConf = new DOM4JConfiguration(new File(testPropertiesXML));
}
public void testAddRemoveConfigurations() throws Exception {
cc.addConfiguration(conf1);
assertEquals(1, cc.getNumberOfConfigurations());
cc.addConfiguration(conf1);
assertEquals(1, cc.getNumberOfConfigurations());
cc.addConfiguration(conf2);
assertEquals(2, cc.getNumberOfConfigurations());
cc.removeConfiguration(conf1);
assertEquals(1, cc.getNumberOfConfigurations());
cc.clear();
assertEquals(0, cc.getNumberOfConfigurations());
}
public void testGetProperty() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(conf2);
assertEquals(
"Make sure we get the property from conf1 first",
"packagea",
cc.getString("packages"));
cc.clear();
cc.addConfiguration(conf2);
cc.addConfiguration(conf1);
assertEquals(
"Make sure we get the property from conf1 first",
"override.packages",
cc.getString("packages"));
}
public void testGetPropertyMissing() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(conf2);
try {
cc.getString("bogus.property");
fail("Should have thrown a java.util.NoSuchElementException");
} catch (java.util.NoSuchElementException nsee) {
}
}
/**
* Tests <code>Vector</code> parsing.
*/
public void testMultipleTypesOfConfigs() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(dom4jConf);
assertEquals(
"Make sure we get the property from conf1 first",
1,
cc.getInt("test.short"));
cc.clear();
cc.addConfiguration(dom4jConf);
cc.addConfiguration(conf1);
assertEquals(
"Make sure we get the property from dom4j",
8,
cc.getInt("test.short"));
}
/**
* Tests <code>Vector</code> parsing.
*/
public void testPropertyExistsInOnlyOneConfig() throws Exception {
cc.addConfiguration(conf1);
cc.addConfiguration(dom4jConf);
assertEquals(
"value",
cc.getString("element"));
}
}
1.1
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestDOM4JConfiguration.java
Index: TestDOM4JConfiguration.java
===================================================================
package org.apache.commons.configuration;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import junit.framework.TestCase;
/**
* test for loading and saving xml properties files
*
* @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
* @version $Id: TestDOM4JConfiguration.java,v 1.1 2003/02/28 20:24:12 epugh Exp $
*/
public class TestDOM4JConfiguration extends TestCase {
/** The File that we test with */
private String testProperties = new File("conf/test.xml").getAbsolutePath();
private DOM4JConfiguration conf;
public TestDOM4JConfiguration(String s) {
super(s);
}
protected void setUp() throws Exception {
conf = new DOM4JConfiguration(new File(testProperties));
}
public void testGetProperty() throws Exception {
assertEquals("value", conf.getProperty("element"));
}
public void testGetComplexProperty() throws Exception {
assertEquals("I'm complex!",
conf.getProperty("element2.subelement.subsubelement"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]