svn commit: r518749 - in /xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom: DocumentTest.java NodeListTest.java NodeTest.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Thu Mar 15 13:38:08 2007
New Revision: 518749

URL: http://svn.apache.org/viewvc?view=rev&rev=518749
Log:
additional tests

Modified:
    xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/DocumentTest.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeListTest.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java

Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/DocumentTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/DocumentTest.java?view=diff&rev=518749&r1=518748&r2=518749
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/DocumentTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/DocumentTest.java Thu Mar 15 13:38:08 2007
@@ -31,14 +31,14 @@
 
     public String getXml() {
         return
-            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
-            "<a xmlns:name=\"http://apache.org\">" +
+            "<?xml version='1.0' encoding='UTF-8'?>" +
+            "<a xmlns:name='http://apache.org'>" +
                 "<b/>" +
-                "<name:c attr1=\"a\" attr2=\"b\">" +
-                    "<d attr3=\"c\" attr4=\"d\" />" +
+                "<name:c attr1='a' attr2='b'>" +
+                    "<d attr3='c' attr4='d'/>" +
                 "</name:c>" +
-                "<c attr1=\"a\" attr2=\"b\">" +
-                    "<d attr3=\"c\" attr4=\"d\" />" +
+                "<c attr1='a' attr2='b'>" +
+                    "<d attr3='c' attr4='d'/>" +
                 "</c>" +
             "</a>";
     }

Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeListTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeListTest.java?view=diff&rev=518749&r1=518748&r2=518749
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeListTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeListTest.java Thu Mar 15 13:38:08 2007
@@ -40,6 +40,13 @@
             "</a>";
     }
 
+    public void testOutOfBounds() throws Exception {
+        NodeList list = root.getChildNodes();
+        assertEquals(3, list.getLength());
+        assertNull(list.item(-1));
+        assertNull(list.item(3));
+    }
+
     public void testElementsByTagName() throws Exception {
         Element element = (Element) root.getFirstChild().getNextSibling();
         assertEquals("c", element.getTagName());

Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java?view=diff&rev=518749&r1=518748&r2=518749
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/dom/NodeTest.java Thu Mar 15 13:38:08 2007
@@ -19,6 +19,7 @@
 
 package org.apache.xindice.xml.dom;
 
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.UserDataHandler;
 
@@ -30,37 +31,70 @@
 
     public String getXml() {
         return
-            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
-            "<a xmlns:name=\"http://apache.org\">" +
-                "<b/>" +
-                "<name:c attr1=\"a\" attr2=\"b\">" +
-                    "<d attr3=\"c\" attr4=\"d\" />" +
+            "<?xml version='1.0' encoding='UTF-8'?>" +
+            "<a xmlns:name='http://apache.org'>" +
+                "<b><a>&lt;common &amp; entities&gt;</a><a><![CDATA[&&& CDATA Section! &&&]]></a></b>" +
+                "<name:c attr1='a' attr2='b'>" +
+                    "<d attr3='c' attr4='d'/>" +
                 "</name:c>" +
-                "<c attr1=\"a\" attr2=\"b\">" +
-                    "<d attr3=\"c\" attr4=\"d\" />" +
+                "<c attr1='a' attr2='b'>" +
+                    "<d attr3='c' attr4='d'/>" +
                 "</c>" +
-                "<name:c attr2=\"b\" attr1=\"a\">" +
-                    "<d attr3=\"c\" attr4=\"d\" />" +
+                "<name:c attr2='b' attr1='a'>" +
+                    "<d attr3='c' attr4='d'/>" +
                 "</name:c>" +
-                "<name:c attr1=\"a\" attr2=\"b\">" +
-                    "<d attr3=\"c\" attr5=\"d\" />" +
+                "<name:c attr1='a' attr2='b'>" +
+                    "<d attr3='c' attr5='d'/>" +
                 "</name:c>" +
                 "<d>Parent text<e>Child text</e></d>" +
+                "<x/>" +
                 "<cmp>" +
                     "<b/>" +
-                    "<c attr1=\"a\" attr2=\"b\">" +
-                        "<d attr3=\"c\" attr4=\"d\">" +
-                            "<e attr=\"1\" />" +
+                    "<c attr1='a' attr2='b'>" +
+                        "<d attr3='c' attr4='d'>" +
+                            "<e attr='1'/>" +
                         "</d>" +
                     "</c>" +
-                    "<f attr1=\"a\" attr2=\"b\">" +
-                        "<d attr3=\"c\" attr4=\"d\" >" +
-                            "<e attr=\"2\" />" +
+                    "<f attr1='a' attr2='b'>" +
+                        "<d attr3='c' attr4='d'>" +
+                            "<e attr='2'/>" +
                         "</d>" +
                     "</f>" +
                     "<d>Parent text<e>Child text</e></d>" +
                 "</cmp>" +
             "</a>";
+    }
+
+    public void testGetFirstChild() {
+        Node n = root.getFirstChild();
+        assertEquals(Node.ELEMENT_NODE, n.getNodeType());
+        assertEquals("b", n.getNodeName());
+
+        n = n.getFirstChild();
+        assertEquals(Node.ELEMENT_NODE, n.getNodeType());
+        assertEquals("a", n.getNodeName());
+
+        n = n.getFirstChild();
+        assertEquals(Node.TEXT_NODE, n.getNodeType());
+
+        n = n.getFirstChild();
+        assertNull(n);
+
+        n = ((Element) root).getElementsByTagName("x").item(0);
+        assertEquals("x", n.getNodeName());
+
+        n = n.getFirstChild();
+        assertNull(n);
+    }
+
+    public void testCommonEntities() {
+        Node n = root.getFirstChild().getFirstChild();
+        assertEquals("<common & entities>", n.getTextContent());
+    }
+
+    public void testCDATA() {
+        Node n = root.getFirstChild().getFirstChild().getNextSibling();
+        assertEquals("&&& CDATA Section! &&&", n.getTextContent());
     }
 
     public void testNodeEquality() throws Exception {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.