ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1308029 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/main/jav...
Date Sun, 01 Apr 2012 08:29:04 GMT
Author: veithen
Date: Sun Apr  1 08:29:03 2012
New Revision: 1308029

URL: http://svn.apache.org/viewvc?rev=1308029&view=rev
Log:
Clarified the specification of the OMElement#setText methods. These methods were implemented
such that they remove only the first child node of type TEXT_NODE (because after calling detach(),
getNextOMSibling() returns null), although the Javadoc (of the implementation) says that it
wipes out "any mixed content". These methods should remove the entire content of the element
before setting the new content.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1308029&r1=1308028&r2=1308029&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
Sun Apr  1 08:29:03 2012
@@ -393,14 +393,26 @@ public interface OMElement extends OMNod
 
     OMElement getFirstElement();
 
-
-    /** @param text  */
+    /**
+     * Set the content of this element to the given text. If the element has children, then
all
+     * these children are detached before the content is set. If the parameter is a non empty
+     * string, then the element will have a single child of type {@link OMText} after the
method
+     * returns. If the parameter is <code>null</code> or an empty string, then
the element will have
+     * no children.
+     * 
+     * @param text
+     *            the new text content for the element
+     */
     void setText(String text);
 
     /**
      * Set the content of this element to the given {@link QName}. If no matching namespace
      * declaration for the {@link QName} is in scope, then this method will add one. If the
-     * {@link QName} specifies a namespace URI but no prefix, then a prefix will be generated.
+     * {@link QName} specifies a namespace URI but no prefix, then a prefix will be generated.
If
+     * the element has children, then all these children are detached before the content
is set. If
+     * the parameter is not <code>null</code>, then the element will have a single
child of type
+     * {@link OMText} after the method returns. If the parameter is <code>null</code>,
then the
+     * element will have no children.
      * 
      * @param qname
      *            the QName value

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1308029&r1=1308028&r2=1308029&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Sun Apr  1 08:29:03 2012
@@ -1020,22 +1020,27 @@ public class ElementImpl extends ParentN
      * @see org.apache.axiom.om.OMElement#setText(String)
      */
     public void setText(String text) {
-        // if we already have other text nodes remove them
-        OMNode child = this.getFirstOMChild();
-        while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
-                child.detach();
-            }
-            child = child.getNextOMSibling();
+        // Remove all existing children
+        OMNode child;
+        while ((child = getFirstOMChild()) != null) {
+            child.detach();
+        }
+        // Add a new text node
+        if (text != null && text.length() > 0) {
+            getOMFactory().createOMText(this, text);
         }
-
-        TextImpl textNode = (TextImpl)ownerDocument()
-                .createTextNode(text);
-        this.addChild(textNode);
     }
 
-    public void setText(QName text) {
-        throw new UnsupportedOperationException();
+    public void setText(QName qname) {
+        // Remove all existing children
+        OMNode child;
+        while ((child = getFirstOMChild()) != null) {
+            child.detach();
+        }
+        // Add a new text node
+        if (qname != null) {
+            getOMFactory().createOMText(this, qname);
+        }
     }
 
     public void internalSerialize(XMLStreamWriter writer,

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1308029&r1=1308028&r2=1308029&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
Sun Apr  1 08:29:03 2012
@@ -31,6 +31,7 @@ import org.apache.axiom.ts.om.element.Te
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
 import org.apache.axiom.ts.om.element.TestSetTextQName;
 import org.apache.axiom.ts.om.element.TestSetTextQNameWithEmptyPrefix;
+import org.apache.axiom.ts.om.element.TestSetTextQNameWithExistingChildren;
 import org.apache.axiom.ts.om.element.TestSetTextQNameWithoutNamespace;
 import org.apache.axiom.ts.om.factory.TestCreateOMElementWithGeneratedPrefix;
 import org.apache.axiom.ts.om.factory.TestCreateOMElementWithNamespaceInScope;
@@ -43,6 +44,7 @@ public class OMImplementationTest extend
         // OMElement#setText(QName) is unsupported
         builder.exclude(TestSetTextQName.class);
         builder.exclude(TestSetTextQNameWithEmptyPrefix.class);
+        builder.exclude(TestSetTextQNameWithExistingChildren.class);
         builder.exclude(TestSetTextQNameWithoutNamespace.class);
         
         // TODO: doesn't work because the test trigger a call to importNode which will build
the descendant

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1308029&r1=1308028&r2=1308029&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Sun Apr  1 08:29:03 2012
@@ -794,34 +794,28 @@ public class OMElementImpl extends OMNod
         return OMContainerHelper.getXMLStreamReader(this, cache, configuration);
     }
 
-    /**
-     * Sets the text of the given element. caution - This method will wipe out all the text
elements
-     * (and hence any mixed content) before setting the text.
-     */
     public void setText(String text) {
-
-        OMNode child = this.getFirstOMChild();
-        while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
-                child.detach();
-            }
-            child = child.getNextOMSibling();
+        // Remove all existing children
+        OMNode child;
+        while ((child = getFirstOMChild()) != null) {
+            child.detach();
+        }
+        // Add a new text node
+        if (text != null && text.length() > 0) {
+            getOMFactory().createOMText(this, text);
         }
-
-        getOMFactory().createOMText(this, text);
     }
 
-    public void setText(QName text) {
-
-        OMNode child = this.getFirstOMChild();
-        while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
-                child.detach();
-            }
-            child = child.getNextOMSibling();
+    public void setText(QName qname) {
+        // Remove all existing children
+        OMNode child;
+        while ((child = getFirstOMChild()) != null) {
+            child.detach();
+        }
+        // Add a new text node
+        if (qname != null) {
+            getOMFactory().createOMText(this, qname);
         }
-
-        getOMFactory().createOMText(this, text);
     }
 
     public String getText() {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java?rev=1308029&r1=1308028&r2=1308029&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java
Sun Apr  1 08:29:03 2012
@@ -127,7 +127,7 @@ public class OMElementTest extends OMTes
                                                testNamespace2.getPrefix()));
 
         firstElement.addChild(secondElement);
-        firstElement.setText("Some Sample Text");
+        factory.createOMText(firstElement, "Some Sample Text");
 
         assertTrue("First added child must be the first child",
                    secondElement.equals(firstElement.getFirstOMChild()));

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=1308029&r1=1308028&r2=1308029&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
Sun Apr  1 08:29:03 2012
@@ -239,8 +239,13 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestSetNamespaceWithNullOMNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetNamespaceWithNullPrefix(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetText(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextEmptyString(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextNull(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextWithExistingChildren(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameNull(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithEmptyPrefix(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithExistingChildren(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithoutNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestUndeclarePrefix(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestWriteTextTo(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java?rev=1308029&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java
Sun Apr  1 08:29:03 2012
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.element;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setText(String)} when invoked with an empty string
as
+ * parameter.
+ */
+public class TestSetTextEmptyString extends AxiomTestCase {
+    public TestSetTextEmptyString(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = metaFactory.getOMFactory().createOMElement("test", null);
+        element.setText("some text");
+        element.setText("");
+        assertNull(element.getFirstOMChild());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextEmptyString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java?rev=1308029&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java
Sun Apr  1 08:29:03 2012
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.element;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setText(String)} when invoked with a <code>null</code>
+ * parameter.
+ */
+public class TestSetTextNull extends AxiomTestCase {
+    public TestSetTextNull(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = metaFactory.getOMFactory().createOMElement("test", null);
+        element.setText("some text");
+        element.setText((String)null);
+        assertNull(element.getFirstOMChild());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextNull.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java?rev=1308029&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java
Sun Apr  1 08:29:03 2012
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.element;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setText(String)} when invoked with a <code>null</code>
+ * parameter.
+ */
+public class TestSetTextQNameNull extends AxiomTestCase {
+    public TestSetTextQNameNull(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = metaFactory.getOMFactory().createOMElement("test", null);
+        element.setText("some text");
+        element.setText((QName)null);
+        assertNull(element.getFirstOMChild());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameNull.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java?rev=1308029&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java
Sun Apr  1 08:29:03 2012
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.element;
+
+import javax.xml.namespace.QName;
+
+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.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setText(QName)} when invoked on an element that
has
+ * children.
+ */
+public class TestSetTextQNameWithExistingChildren extends AxiomTestCase {
+    public TestSetTextQNameWithExistingChildren(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement("TestElement", null);
+        
+        // Add some children of various types
+        factory.createOMText(element, "some text");
+        factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
+        factory.createOMComment(element, "comment");
+        factory.createOMProcessingInstruction(element, "piTarget", "piData");
+        factory.createOMElement("child", null, element);
+
+        QName qname = new QName("urn:ns1", "test", "ns");
+        element.setText(qname);
+
+        assertEquals("ns:test", element.getText());
+
+        // Check that OMElement#setText() has created the expected nodes
+        OMNode child = element.getFirstOMChild();
+        assertTrue(child instanceof OMText);
+        assertSame(element, child.getParent());
+        assertEquals("ns:test", ((OMText)child).getText());
+        assertNull(child.getNextOMSibling());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQNameWithExistingChildren.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java?rev=1308029&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java
Sun Apr  1 08:29:03 2012
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.element;
+
+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.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setText(String)} when invoked on an element that
has
+ * children.
+ */
+public class TestSetTextWithExistingChildren extends AxiomTestCase {
+    public TestSetTextWithExistingChildren(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement("test", null);
+        
+        // Add some children of various types
+        factory.createOMText(element, "some text");
+        factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
+        factory.createOMComment(element, "comment");
+        factory.createOMProcessingInstruction(element, "piTarget", "piData");
+        factory.createOMElement("child", null, element);
+
+        // Set the text; this should remove all child nodes
+        element.setText("test");
+        
+        // Check that OMElement#getText() returns a matching value
+        assertEquals("Text value mismatch", "test", element.getText());
+        
+        // Check that OMElement#setText() has created the expected nodes
+        OMNode child = element.getFirstOMChild();
+        assertTrue(child instanceof OMText);
+        assertSame(element, child.getParent());
+        assertEquals("test", ((OMText)child).getText());
+        assertNull(child.getNextOMSibling());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextWithExistingChildren.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message