Author: veithen
Date: Tue Dec 16 18:52:18 2008
New Revision: 727247

URL: http://svn.apache.org/viewvc?rev=727247&view=rev
Log:
WSCOMMONS-337: Fixed an issue where OMNode#insertSiblingAfter didn't update the 
parent's last child. This issue was reported by Saliya Ekanayake and affected 
both LLOM and DOM. Also added the test case provided by Saliya to 
OMElementTestBase, so that it gets executed for the two OM implementations.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=727247&r1=727246&r2=727247&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
 Tue Dec 16 18:52:18 2008
@@ -154,7 +154,9 @@
         if (sibling instanceof ChildNode) {
             ChildNode domSibling = (ChildNode) sibling;
             domSibling.previousSibling = this;
-            if (this.nextSibling != null) {
+            if (this.nextSibling == null) {
+                this.parentNode.setLastChild(sibling);
+            } else {
                 this.nextSibling.previousSibling = domSibling;
             }
             domSibling.nextSibling = this.nextSibling;

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=727247&r1=727246&r2=727247&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
 Tue Dec 16 18:52:18 2008
@@ -234,7 +234,9 @@
                 getNextOMSibling();
             }
             siblingImpl.setPreviousOMSibling(this);
-            if (nextSibling != null) {
+            if (nextSibling == null) {
+                parent.setLastChild(sibling);
+            } else {
                 nextSibling.setPreviousOMSibling(sibling);
             }
             ((OMNodeEx) sibling).setNextOMSibling(nextSibling);

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java?rev=727247&r1=727246&r2=727247&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMElementTestBase.java
 Tue Dec 16 18:52:18 2008
@@ -80,4 +80,25 @@
         }
         assertEquals("In correct number of children", 1, count);
     }
+    
+    // Regression test for WSCOMMONS-337
+    public void testInsertSiblingAfterLastChild() throws Exception {
+        OMFactory fac = getOMFactory();
+        OMNamespace ns = fac.createOMNamespace("http://www.testuri.com","ns";);
+        OMElement parent = fac.createOMElement("parent", ns);
+        
+        // Create three OMElements
+        OMElement c1 = fac.createOMElement("c1", ns);
+        OMElement c2 = fac.createOMElement("c2", ns);
+        OMElement c3 = fac.createOMElement("c3", ns);
+
+        // Add c1 to parent using parent.addChild()
+        parent.addChild(c1);
+        // Add c2 to c1 as a sibling after
+        c1.insertSiblingAfter(c2);
+        // Now add c3 to parent using parent.addChild()
+        parent.addChild(c3);
+        assertXMLEqual("<ns:parent xmlns:ns=\"http://www.testuri.com\";>" +
+                "<ns:c1 /><ns:c2 /><ns:c3 /></ns:parent>", parent.toString());
+    }
 }


Reply via email to