commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r604239 - /commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java
Date Fri, 14 Dec 2007 17:34:09 GMT
Author: mbenson
Date: Fri Dec 14 09:34:08 2007
New Revision: 604239

URL: http://svn.apache.org/viewvc?rev=604239&view=rev
Log:
[JXPATH-105] test basicnodeset nodes

Modified:
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java?rev=604239&r1=604238&r2=604239&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java (original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/BasicNodeSetTest.java Fri
Dec 14 09:34:08 2007
@@ -17,6 +17,9 @@
 package org.apache.commons.jxpath;
 
 import java.util.Iterator;
+import java.util.List;
+
+import org.w3c.dom.Element;
 
 /**
  * Test BasicNodeSet
@@ -26,6 +29,7 @@
  *          2007) $
  */
 public class BasicNodeSetTest extends JXPathTestCase {
+
     /** JXPathContext */
     protected JXPathContext context;
 
@@ -46,7 +50,7 @@
      */
     protected void setUp() throws Exception {
         super.setUp();
-        context = JXPathContext.newContext(new TestBean());
+        context = JXPathContext.newContext(new TestMixedModelBean());
         nodeSet = new BasicNodeSet();
     }
 
@@ -87,9 +91,9 @@
      * Test adding pointers.
      */
     public void testAdd() {
-        addPointers("/integers");
-        assertEquals(nodeSet.getPointers().toString(), list("/integers[1]",
-                "/integers[2]", "/integers[3]", "/integers[4]").toString());
+        addPointers("/bean/integers");
+        assertEquals(nodeSet.getPointers().toString(), list("/bean/integers[1]",
+                "/bean/integers[2]", "/bean/integers[3]", "/bean/integers[4]").toString());
         assertEquals(list(new Integer(1), new Integer(2), new Integer(3),
                 new Integer(4)), nodeSet.getValues());
         assertEquals(list(new Integer(1), new Integer(2), new Integer(3),
@@ -100,9 +104,9 @@
      * Test removing a pointer.
      */
     public void testRemove() {
-        addPointers("/integers");
-        removePointers("/integers[4]");
-        assertEquals(list("/integers[1]", "/integers[2]", "/integers[3]")
+        addPointers("/bean/integers");
+        removePointers("/bean/integers[4]");
+        assertEquals(list("/bean/integers[1]", "/bean/integers[2]", "/bean/integers[3]")
                 .toString(), nodeSet.getPointers().toString());
         assertEquals(list(new Integer(1), new Integer(2), new Integer(3)),
                 nodeSet.getValues());
@@ -110,4 +114,48 @@
                 nodeSet.getNodes());
     }
 
+    /**
+     * Demonstrate when nodes != values:  in XML models.
+     */
+    public void testNodes() {
+        addPointers("/document/vendor/contact");
+        assertEquals(list("/document/vendor[1]/contact[1]",
+                "/document/vendor[1]/contact[2]",
+                "/document/vendor[1]/contact[3]",
+                "/document/vendor[1]/contact[4]").toString(),
+                nodeSet.getPointers().toString());
+        assertEquals(list("John", "Jack", "Jim", "Jack Black"),
+                nodeSet.getValues());
+        assertElementNames(list("contact", "contact", "contact", "contact"), nodeSet.getNodes());
+        assertElementValues(list("John", "Jack", "Jim", "Jack Black"), nodeSet.getNodes());
+    }
+
+    /**
+     * Do assertions on DOM element names.
+     * @param names List of expected names
+     * @param elements List of DOM elements
+     */
+    protected void assertElementNames(List names, List elements) {
+        assertEquals(names.size(), elements.size());
+        Iterator nameIter = names.iterator();
+        Iterator elementIter = elements.iterator();
+        while (elementIter.hasNext()) {
+            assertEquals(nameIter.next(), ((Element) elementIter.next()).getTagName());
+        }
+    }
+
+    /**
+     * Do assertions on DOM element values.
+     * @param values List of expected values
+     * @param elements List of DOM elements
+     */
+    protected void assertElementValues(List values, List elements) {
+        assertEquals(values.size(), elements.size());
+        Iterator valueIter = values.iterator();
+        Iterator elementIter = elements.iterator();
+        while (elementIter.hasNext()) {
+            assertEquals(valueIter.next(), ((Element) elementIter.next()).getFirstChild().getNodeValue());
+        }
+        
+    }
 }



Mime
View raw message