epugh 2003/03/19 02:32:46
Modified: configuration/src/test/org/apache/commons/configuration
TestCompositeConfiguration.java
TestConfigurationFactory.java
TestDOM4JConfiguration.java
TestPropertiesConfiguration.java
Log:
Test cases for fixes to support being able to setProperties and clearProperties.
Revision Changes Path
1.4 +171 -128
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
Index: TestCompositeConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestCompositeConfiguration.java 18 Mar 2003 21:43:48 -0000 1.3
+++ TestCompositeConfiguration.java 19 Mar 2003 10:32:46 -0000 1.4
@@ -67,132 +67,175 @@
*/
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"));
- }
-
- /**
- * Tests getting a default when the key doesn't exist
- */
- public void testDefaultValueWhenKeyMissing() throws Exception
- {
- cc.addConfiguration(conf1);
- cc.addConfiguration(dom4jConf);
- assertEquals("default", cc.getString("bogus","default"));
- assertTrue(1.4==cc.getDouble("bogus",1.4));
- assertTrue(1.4==cc.getDouble("bogus",1.4));
- }
-
- /**
- * Tests <code>Vector</code> parsing.
- */
- public void testGettingConfiguration() throws Exception
- {
- cc.addConfiguration(conf1);
- cc.addConfiguration(dom4jConf);
- assertEquals(PropertiesConfiguration.class,
cc.getConfiguration(0).getClass());
- assertEquals(DOM4JConfiguration.class,
cc.getConfiguration(1).getClass());
- }
+ 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(2, cc.getNumberOfConfigurations());
+ cc.addConfiguration(conf1);
+ assertEquals(2, cc.getNumberOfConfigurations());
+ cc.addConfiguration(conf2);
+ assertEquals(3, cc.getNumberOfConfigurations());
+ cc.removeConfiguration(conf1);
+ assertEquals(2, cc.getNumberOfConfigurations());
+ cc.clear();
+ assertEquals(1, 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"));
+ }
+
+ /**
+ * Tests getting a default when the key doesn't exist
+ */
+ public void testDefaultValueWhenKeyMissing() throws Exception
+ {
+ cc.addConfiguration(conf1);
+ cc.addConfiguration(dom4jConf);
+ assertEquals("default", cc.getString("bogus", "default"));
+ assertTrue(1.4 == cc.getDouble("bogus", 1.4));
+ assertTrue(1.4 == cc.getDouble("bogus", 1.4));
+ }
+
+ /**
+ * Tests <code>Vector</code> parsing.
+ */
+ public void testGettingConfiguration() throws Exception
+ {
+ cc.addConfiguration(conf1);
+ cc.addConfiguration(dom4jConf);
+ assertEquals(
+ PropertiesConfiguration.class,
+ cc.getConfiguration(1).getClass());
+ assertEquals(
+ DOM4JConfiguration.class,
+ cc.getConfiguration(2).getClass());
+ }
+
+ /**
+ * Tests setting values. These are set in memory mode only!
+ */
+ public void testClearingProperty() throws Exception
+ {
+
+ cc.addConfiguration(conf1);
+ cc.addConfiguration(dom4jConf);
+ cc.clearProperty("test.short");
+ assertTrue(
+ "Make sure test.short is gone!",
+ !cc.containsKey("test.short"));
+ }
+
+ /**
+ * Tests adding values. Make sure they override any other properties!
+ */
+ public void testAddingProperty() throws Exception
+ {
+
+ cc.addConfiguration(conf1);
+ cc.addConfiguration(dom4jConf);
+
+ cc.addProperty("test.short", "88");
+ assertEquals(
+ "Make sure test.short is overridden!",
+ "88",
+ cc.getString("test.short"));
+ }
+
+ /**
+ * Tests setting values. These are set in memory mode only!
+ */
+ public void testSettingMissingProperty() throws Exception
+ {
+ cc.addConfiguration(conf1);
+ cc.addConfiguration(dom4jConf);
+ cc.setProperty("my.new.property", "supernew");
+ assertEquals("supernew", cc.getString("my.new.property"));
+
+ }
-
}
1.2 +9 -9
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
Index: TestConfigurationFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestConfigurationFactory.java 18 Mar 2003 21:44:14 -0000 1.1
+++ TestConfigurationFactory.java 19 Mar 2003 10:32:46 -0000 1.2
@@ -96,9 +96,9 @@
compositeConfiguration = (CompositeConfiguration)
configurationFactory.getConfiguration();
- assertEquals("Verify how many configs", 2,
compositeConfiguration.getNumberOfConfigurations());
- assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(0).getClass());
- PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(0);
+ assertEquals("Verify how many configs", 3,
compositeConfiguration.getNumberOfConfigurations());
+ assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(1).getClass());
+ PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(1);
assertNotNull("Make sure we have a fileName:" + pc.getFileName(),
pc.getFileName());
@@ -132,11 +132,11 @@
compositeConfiguration = (CompositeConfiguration)
configurationFactory.getConfiguration();
- assertEquals("Verify how many configs", 2,
compositeConfiguration.getNumberOfConfigurations());
+ assertEquals("Verify how many configs", 3,
compositeConfiguration.getNumberOfConfigurations());
- assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(0).getClass());
+ assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(1).getClass());
- PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(0);
+ PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(1);
assertNotNull("Make sure we have a fileName:" + pc.getFileName(),
pc.getFileName());
assertTrue("Make sure we have loaded our key",
pc.getBoolean("test.boolean"));
@@ -157,11 +157,11 @@
compositeConfiguration = (CompositeConfiguration)
configurationFactory.getConfiguration();
- assertEquals("Verify how many configs", 1,
compositeConfiguration.getNumberOfConfigurations());
+ assertEquals("Verify how many configs", 2,
compositeConfiguration.getNumberOfConfigurations());
- assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(0).getClass());
+ assertEquals(PropertiesConfiguration.class,
compositeConfiguration.getConfiguration(1).getClass());
- PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(0);
+ PropertiesConfiguration pc = (PropertiesConfiguration)
compositeConfiguration.getConfiguration(1);
assertNotNull("Make sure we have a fileName:" + pc.getFileName(),
pc.getFileName());
assertTrue("Make sure we have loaded our key",
pc.getBoolean("test.boolean"));
1.3 +0 -0
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestDOM4JConfiguration.java
Index: TestDOM4JConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestDOM4JConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
1.8 +0 -0
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Index: TestPropertiesConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]