You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/01/19 12:21:23 UTC

svn commit: r1435523 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/

Author: veithen
Date: Sat Jan 19 11:21:23 2013
New Revision: 1435523

URL: http://svn.apache.org/viewvc?rev=1435523&view=rev
Log:
Generalized the TestDetach test case and fixed an issue that causes corruption of the internal state of LLOM's OMDocument implementation.

Modified:
    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-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java

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=1435523&r1=1435522&r2=1435523&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 Sat Jan 19 11:21:23 2013
@@ -141,14 +141,12 @@ public abstract class OMNodeImpl extends
         if (previousSibling == null) {
             parent.setFirstChild(nextSibling);
         } else {
-            ((OMNodeEx) getPreviousOMSibling()).setNextOMSibling(nextSibling);
+            previousSibling.setNextOMSibling(nextSibling);
         }
-        if (nextSibling != null) {
-            nextSibling.setPreviousOMSibling(getPreviousOMSibling());
-        }
-
-        if ((parent instanceof OMElementImpl) && ((OMElementImpl) parent).lastChild == this) {
-            ((OMElementImpl) parent).lastChild = getPreviousOMSibling();
+        if (nextSibling == null) {
+            parent.setLastChild(previousSibling);
+        } else {
+            nextSibling.setPreviousOMSibling(previousSibling);
         }
 
         this.previousSibling = null;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1435523&r1=1435522&r2=1435523&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sat Jan 19 11:21:23 2013
@@ -421,8 +421,10 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.namespace.TestObjectEquals(metaFactory));
         addTest(new org.apache.axiom.ts.om.namespace.TestObjectEqualsWithDifferentPrefixes(metaFactory));
         addTest(new org.apache.axiom.ts.om.namespace.TestObjectEqualsWithDifferentURIs(metaFactory));
-        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, true));
-        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, false));
+        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, true, true));
+        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, true, false));
+        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, false, true));
+        addTest(new org.apache.axiom.ts.om.node.TestDetach(metaFactory, false, false));
         addTest(new org.apache.axiom.ts.om.node.TestDetachAfterBuilderClose(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestDetachFirstChild(metaFactory, true));
         addTest(new org.apache.axiom.ts.om.node.TestDetachFirstChild(metaFactory, false));

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java?rev=1435523&r1=1435522&r2=1435523&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestDetach.java Sat Jan 19 11:21:23 2013
@@ -18,33 +18,49 @@
  */
 package org.apache.axiom.ts.om.node;
 
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMComment;
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.axiom.ts.AxiomTestCase;
 
 /**
  * Tests the behavior of {@link OMNode#detach()}.
  */
 public class TestDetach extends AxiomTestCase {
+    private final boolean document;
     private final boolean build;
     
-    public TestDetach(OMMetaFactory metaFactory, boolean build) {
+    public TestDetach(OMMetaFactory metaFactory, boolean document, boolean build) {
         super(metaFactory);
+        this.document = document;
         this.build = build;
+        addTestProperty("document", Boolean.toString(document));
         addTestProperty("build", Boolean.toString(build));
     }
 
     protected void runTest() throws Throwable {
-        OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<root><a/><b/><c/></root>");
+        OMFactory factory = metaFactory.getOMFactory();
+        OMContainer root;
+        if (document) {
+            root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(
+                    "<!--a--><b/><!--c-->")).getDocument();
+        } else {
+            root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(
+                    "<root><!--a--><b/><!--c--></root>")).getDocumentElement();
+        }
         if (build) {
             root.build();
         } else {
             assertFalse(root.isComplete());
         }
-        OMElement a = (OMElement)root.getFirstOMChild();
-        assertEquals("a", a.getLocalName());
+        OMComment a = (OMComment)root.getFirstOMChild();
+        assertEquals("a", a.getValue());
         OMElement b = (OMElement)a.getNextOMSibling();
         assertEquals("b", b.getLocalName());
         OMNode returnValue = b.detach();
@@ -52,8 +68,8 @@ public class TestDetach extends AxiomTes
         assertNull(b.getParent());
         assertNull(b.getPreviousOMSibling());
         assertNull(b.getNextOMSibling());
-        OMElement c = (OMElement)a.getNextOMSibling();
-        assertEquals("c", c.getLocalName());
+        OMComment c = (OMComment)a.getNextOMSibling();
+        assertEquals("c", c.getValue());
         assertSame(c, a.getNextOMSibling());
         assertSame(a, c.getPreviousOMSibling());
         root.close(false);