Author: veithen
Date: Sat Oct  1 12:56:31 2011
New Revision: 1177972

URL: http://svn.apache.org/viewvc?rev=1177972&view=rev
Log:
AXIOM-311: Rationalized the test cases for OMElement#getText() and 
OMElement#setText().

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetText.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithCDATASectionChild.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithMixedOMTextChildren.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetText.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java?rev=1177972&r1=1177971&r2=1177972&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
 Sat Oct  1 12:56:31 2011
@@ -22,7 +22,6 @@ package org.apache.axiom.om;
 import java.util.Iterator;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
 
 import org.apache.axiom.om.util.AXIOMUtil;
 
@@ -33,35 +32,6 @@ public abstract class OMElementTestBase 
         this.omMetaFactory = omMetaFactory;
     }
 
-    public void testSetText() {
-        OMFactory factory = omMetaFactory.getOMFactory();
-        String localName = "TestLocalName";
-        String namespace = "http://ws.apache.org/axis2/ns";;
-        String prefix = "axis2";
-        OMElement elem = factory.createOMElement(localName, namespace, prefix);
-
-        String text = "The quick brown fox jumps over the lazy dog";
-
-        elem.setText(text);
-
-        assertEquals("Text value mismatch", text, elem.getText());
-    }
-
-    public void testCDATA() throws Exception {
-        OMFactory factory = omMetaFactory.getOMFactory();
-        OMElement omElement = factory.createOMElement("TestElement", null);
-        final String text = "this is <some> text in a CDATA";
-        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
-        assertEquals(text, omElement.getText());
-
-        // OK, CDATA on its own worked - now confirm that a plain text + a 
CDATA works
-        omElement = factory.createOMElement("element2", null);
-        final String normalText = "regular text and ";
-        factory.createOMText(omElement, normalText);
-        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
-        assertEquals(normalText + text, omElement.getText());
-    }
-    
     public void testAddChild() {
         OMFactory factory = omMetaFactory.getOMFactory();
         String localName = "TestLocalName";

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1177972&r1=1177971&r2=1177972&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
 Sat Oct  1 12:56:31 2011
@@ -145,6 +145,9 @@ public class OMTestSuiteBuilder extends 
         addTest(new 
org.apache.axiom.ts.om.element.TestGetNamespaceURIWithoutNamespace(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetQNameWithNamespace(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetQNameWithoutNamespace(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetText(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestGetTextWithCDATASectionChild(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestGetTextWithMixedOMTextChildren(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCommentEvent(metaFactory));

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetText.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetText.java?rev=1177972&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetText.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetText.java
 Sat Oct  1 12:56:31 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#getText()} when invoked on an 
element with a single child
+ * of type {@link OMText}.
+ */
+public class TestGetText extends AxiomTestCase {
+    public TestGetText(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement("test", null);
+        String text = "The quick brown fox jumps over the lazy dog";
+        factory.createOMText(element, text);
+        assertEquals("Text value mismatch", text, element.getText());
+    }
+}

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

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithCDATASectionChild.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithCDATASectionChild.java?rev=1177972&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithCDATASectionChild.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithCDATASectionChild.java
 Sat Oct  1 12:56:31 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.stream.XMLStreamConstants;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#getText()} when invoked on an 
element containing both a
+ * text node and a CDATA section.
+ */
+public class TestGetTextWithCDATASectionChild extends AxiomTestCase {
+    public TestGetTextWithCDATASectionChild(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement omElement = factory.createOMElement("TestElement", null);
+        final String text = "this is <some> text in a CDATA";
+        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
+        assertEquals(text, omElement.getText());
+    }
+}

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

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithMixedOMTextChildren.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithMixedOMTextChildren.java?rev=1177972&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithMixedOMTextChildren.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetTextWithMixedOMTextChildren.java
 Sat Oct  1 12:56:31 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.stream.XMLStreamConstants;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#getText()} when invoked on an 
element containing a single
+ * CDATA section.
+ */
+public class TestGetTextWithMixedOMTextChildren extends AxiomTestCase {
+    public TestGetTextWithMixedOMTextChildren(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement omElement = factory.createOMElement("element2", null);
+        final String normalText = "regular text and ";
+        final String text = "this is <some> text in a CDATA";
+        factory.createOMText(omElement, normalText);
+        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
+        assertEquals(normalText + text, omElement.getText());
+    }
+}

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

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetText.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetText.java?rev=1177972&r1=1177971&r2=1177972&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetText.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetText.java
 Sat Oct  1 12:56:31 2011
@@ -24,6 +24,9 @@ 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()} when invoked on an empty 
element.
+ */
 public class TestSetText extends AxiomTestCase {
     public TestSetText(OMMetaFactory metaFactory) {
         super(metaFactory);
@@ -31,11 +34,17 @@ public class TestSetText extends AxiomTe
 
     protected void runTest() throws Throwable {
         OMElement element = metaFactory.getOMFactory().createOMElement("test", 
null);
-        element.setText("text");
+        String text = "The quick brown fox jumps over the lazy dog";
+        element.setText(text);
+        
+        // Check that OMElement#getText() returns a matching value
+        assertEquals("Text value mismatch", text, element.getText());
+        
+        // Check that OMElement#setText() has created the expected nodes
         OMNode child = element.getFirstOMChild();
         assertTrue(child instanceof OMText);
         assertSame(element, child.getParent());
-        assertEquals("text", ((OMText)child).getText());
+        assertEquals(text, ((OMText)child).getText());
         assertNull(child.getNextOMSibling());
     }
 }


Reply via email to