ebourg 2004/07/12 07:38:29
Modified: configuration/conf test.xml
configuration/src/test/org/apache/commons/configuration
TestXMLConfiguration.java
Log:
Better test coverage (addProperty on non initialiazed configurations and attribute
properties tests)
Revision Changes Path
1.2 +11 -10 jakarta-commons/configuration/conf/test.xml
Index: test.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/conf/test.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- test.xml 23 Dec 2003 15:09:05 -0000 1.1
+++ test.xml 12 Jul 2004 14:38:29 -0000 1.2
@@ -1,11 +1,12 @@
<baseElement>
- <element>value</element>
- <element2>
- <subelement>
- <subsubelement>I'm complex!</subsubelement>
- </subelement>
- </element2>
- <test>
- <short>8</short>
- </test>
-</baseElement>
\ No newline at end of file
+ <element>value</element>
+ <element2>
+ <subelement>
+ <subsubelement>I'm complex!</subsubelement>
+ </subelement>
+ </element2>
+ <element3 name="foo">value</element3>
+ <test>
+ <short>8</short>
+ </test>
+</baseElement>
1.2 +41 -3
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Index: TestXMLConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestXMLConfiguration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestXMLConfiguration.java 12 Jul 2004 12:14:38 -0000 1.1
+++ TestXMLConfiguration.java 12 Jul 2004 14:38:29 -0000 1.2
@@ -17,6 +17,7 @@
package org.apache.commons.configuration;
import java.io.File;
+import java.util.List;
import junit.framework.TestCase;
@@ -42,6 +43,34 @@
assertEquals("value", conf.getProperty("element"));
}
+ public void testGetAttribute() throws Exception
+ {
+ assertEquals("element3{name}", "foo", conf.getProperty("[EMAIL
PROTECTED]"));
+ }
+
+ public void testClearAttribute() throws Exception
+ {
+ conf.clearProperty("[EMAIL PROTECTED]");
+ assertEquals("[EMAIL PROTECTED]", null, conf.getProperty("[EMAIL
PROTECTED]"));
+ }
+
+ public void testSetAttribute() throws Exception
+ {
+ conf.setProperty("[EMAIL PROTECTED]", "bar");
+ assertEquals("[EMAIL PROTECTED]", "bar", conf.getProperty("[EMAIL
PROTECTED]"));
+ }
+
+ public void testAddAttribute() throws Exception
+ {
+ conf.addProperty("[EMAIL PROTECTED]", "bar");
+
+ List list = conf.getList("[EMAIL PROTECTED]");
+ assertNotNull("null list", list);
+ assertTrue("'foo' element missing", list.contains("foo"));
+ assertTrue("'bar' element missing", list.contains("bar"));
+ assertEquals("list size", 2, list.size());
+ }
+
public void testGetComplexProperty() throws Exception
{
assertEquals("I'm complex!",
conf.getProperty("element2.subelement.subsubelement"));
@@ -74,15 +103,24 @@
assertEquals("I'm complex!",
conf.getProperty("element2.subelement.subsubelement"));
}
-
+
public void testLoadWithBasePath() throws Exception
{
conf = new XMLConfiguration();
-
+
conf.setFileName("test.xml");
conf.setBasePath(testBasePath);
conf.load();
assertEquals("I'm complex!",
conf.getProperty("element2.subelement.subsubelement"));
+ }
+
+ public void testAddProperty()
+ {
+ // add a property to a non initialized xml configuration
+ XMLConfiguration config = new XMLConfiguration();
+ config.addProperty("test.string", "hello");
+
+ assertEquals("'test.string'", "hello", config.getString("test.string"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]