You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ep...@apache.org on 2004/09/06 15:12:05 UTC
cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestHierarchicalXMLConfiguration.java
epugh 2004/09/06 06:12:04
Modified: configuration/xdocs changes.xml
configuration/src/test/org/apache/commons/configuration
TestHierarchicalXMLConfiguration.java
Added: configuration/conf testHierarchicalXMLConfiguration2.xml
Log:
30597 Test cases for HierarchicalConfigurationXMLReader stores comments as text nodes
Revision Changes Path
1.40 +3 -0 jakarta-commons/configuration/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- changes.xml 6 Sep 2004 12:52:12 -0000 1.39
+++ changes.xml 6 Sep 2004 13:12:04 -0000 1.40
@@ -7,6 +7,9 @@
<body>
<release version="1.0-rc2" date="in CVS">
+ <action dev="epugh" type="fix" issue="30597" due-to="Mark Woodman">
+ Test cases for HierarchicalConfigurationXMLReader stores comments as text nodes
+ </action>
<action dev="epugh" type="fix" issue="30545" due-to="Ricardo Gladwell">
Clarify for ConfigurationDynaBean that the get method should throw an illegalArgumentException
if there is no property specified.
1.1 jakarta-commons/configuration/conf/testHierarchicalXMLConfiguration2.xml
Index: testHierarchicalXMLConfiguration2.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Test config to confirm proper consumption of various XML nodes. -->
<config>
<case1>
<!-- Comment contained in element. -->
Case1Text
</case1>
<case2>
<!-- Comment sibling to element. -->
<child>
Case2Text
</child>
</case2>
<case3>
<!-- Comment sibling to CDATA. -->
<![CDATA[
Case3Text
]]>
</case3>
<case4>
<!-- Comment sibling to PI and text. -->
<?xml-stylesheet href="pi.css" type="text/css" ?>
Case4Text
</case4>
<case5 attr="Case5Text">
<!-- Comment in element with text in attribute -->
</case5>
</config>
1.2 +60 -7 jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java
Index: TestHierarchicalXMLConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestHierarchicalXMLConfiguration.java 12 Jul 2004 12:14:38 -0000 1.1
+++ TestHierarchicalXMLConfiguration.java 6 Sep 2004 13:12:04 -0000 1.2
@@ -16,26 +16,40 @@
* limitations under the License.
*/
+import junit.framework.TestCase;
+
import java.io.File;
import java.util.Collection;
-
-import junit.framework.TestCase;
+import java.util.Iterator;
/**
* Test class for HierarchicalXMLConfiguration,
*
+ * @author Emmanuel Bourg
+ * @author Mark Woodman
* @version $Id$
*/
public class TestHierarchicalXMLConfiguration extends TestCase
{
+ /** Test resources directory. */
private static final String TEST_DIR = "conf";
-
+
+ /** Test file #1 **/
private static final String TEST_FILENAME = "testHierarchicalXMLConfiguration.xml";
-
+
+ /** Test file #2 **/
+ private static final String TEST_FILENAME2 = "testHierarchicalXMLConfiguration2.xml";
+
+ /** Test file path #1 **/
private static final String TEST_FILE = TEST_DIR + File.separator + TEST_FILENAME;
-
+
+ /** Test file path #2 **/
+ private static final String TEST_FILE2 = TEST_DIR + File.separator + TEST_FILENAME2;
+
+ /** Instance config used for tests. */
private HierarchicalXMLConfiguration config;
-
+
+ /** Fixture setup. */
protected void setUp() throws Exception
{
config = new HierarchicalXMLConfiguration();
@@ -92,4 +106,43 @@
config.load();
configTest(config);
}
+
+ /**
+ * Ensure various node types are correctly processed in config.
+ * @throws Exception
+ */
+ public void testXmlNodeTypes() throws Exception
+ {
+ // Number of keys expected from test configuration file
+ final int KEY_COUNT = 5;
+
+ // Load the configuration file
+ config.load(new File(TEST_FILE2).getAbsoluteFile().toURL());
+
+ // Validate comment in element ignored
+ assertEquals("Comment in element must not change element value.", "Case1Text", config.getString("case1"));
+
+ // Validate sibling comment ignored
+ assertEquals("Comment as sibling must not change element value.", "Case2Text", config.getString("case2.child"));
+
+ // Validate comment ignored, CDATA processed
+ assertEquals("Comment and use of CDATA must not change element value.", "Case3Text", config.getString("case3"));
+
+ // Validate comment and processing instruction ignored
+ assertEquals("Comment and use of PI must not change element value.", "Case4Text", config.getString("case4"));
+
+ // Validate comment ignored in parent attribute
+ assertEquals("Comment must not change attribute node value.", "Case5Text", config.getString("case5[@attr]"));
+
+ // Validate non-text nodes haven't snuck in as keys
+ Iterator iter = config.getKeys();
+ int count = 0;
+ while (iter.hasNext())
+ {
+ iter.next();
+ count++;
+ }
+ assertEquals("Config must contain only " + KEY_COUNT + " keys.", KEY_COUNT, count);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org