You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/06/17 00:32:05 UTC

svn commit: r785435 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/om/ axiom-tests/src/test/java/org/apache/axiom/om/

Author: veithen
Date: Tue Jun 16 22:32:05 2009
New Revision: 785435

URL: http://svn.apache.org/viewvc?rev=785435&view=rev
Log:
Moved some OMElement related test cases to a better place.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java?rev=785435&r1=785434&r2=785435&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java Tue Jun 16 22:32:05 2009
@@ -30,7 +30,11 @@
 import javax.activation.DataSource;
 import javax.activation.URLDataSource;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
 
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.custommonkey.xmlunit.XMLTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentType;
@@ -89,6 +93,17 @@
         return in;
     }
     
+    public OMElement getTestResourceAsElement(OMMetaFactory omMetaFactory, String relativePath) {
+        try {
+            return new StAXOMBuilder(omMetaFactory.getOMFactory(),
+                    XMLInputFactory.newInstance().createXMLStreamReader(
+                            getTestResource(relativePath))).getDocumentElement();
+        } catch (Exception ex) {
+            fail("Unable to load test file " + relativePath + ": " + ex.getMessage());
+            return null; // Make compiler happy
+        }
+    }
+    
     public static String[] getConformanceTestFiles() throws Exception {
         BufferedReader in = new BufferedReader(new InputStreamReader(
                 AbstractTestCase.class.getClassLoader().getResourceAsStream(

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=785435&r1=785434&r2=785435&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 Tue Jun 16 22:32:05 2009
@@ -25,6 +25,7 @@
 import javax.xml.stream.XMLStreamConstants;
 
 import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.soap.SOAP11Constants;
 
 public abstract class OMElementTestBase extends AbstractTestCase {
     protected final OMMetaFactory omMetaFactory;
@@ -33,6 +34,131 @@
         this.omMetaFactory = omMetaFactory;
     }
 
+    /** Test the plain iterator which includes all the children (including the texts) */
+    public void testGetChildren() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildren();
+        int counter = 0;
+        while (iter.hasNext()) {
+            counter ++;
+            assertNotNull("Must return not null objects!", iter.next());
+        }
+        assertEquals("This element should contain only five children including the text ", 5,
+                     counter);
+    }
+
+    /** test the remove exception behavior */
+    public void testGetChildrenRemove1() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildren();
+
+        //this is supposed to throw an illegal state exception
+        try {
+            iter.remove();
+            fail("remove should throw an exception");
+        } catch (IllegalStateException e) {
+            //ok. this is what should happen
+        }
+
+    }
+
+    /** test the remove exception behavior, consecutive remove calls */
+    public void testGetChildrenRemove2() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildren();
+        if (iter.hasNext()) {
+            iter.next();
+        }
+        iter.remove();
+
+        //this call must generate an exception
+        try {
+            iter.remove();
+            fail("calling remove twice without a call to next is prohibited");
+        } catch (IllegalStateException e) {
+            //ok if we come here :)
+        }
+
+    }
+
+    /** Remove all! */
+    public void testGetChildrenRemove3() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildren();
+        while (iter.hasNext()) {
+            iter.next();
+            iter.remove();
+        }
+        iter = elt.getChildren();
+        if (iter.hasNext()) {
+            //we shouldn't reach here!
+            fail("No children should remain after removing all!");
+        }
+
+
+    }
+
+    /** test whether the children count reduces. */
+    public void testGetChildrenRemove4() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildren();
+        int firstChildrenCount = 0;
+        int secondChildrenCount = 0;
+        while (iter.hasNext()) {
+            assertNotNull(iter.next());
+            firstChildrenCount++;
+        }
+
+        //remove the last node
+        iter.remove();
+
+        //reloop and check the count
+        //Note- here we should get a fresh iterator since there is no method to
+        //reset the iterator
+        iter = elt.getChildren(); //reset the iterator
+        while (iter.hasNext()) {
+            assertNotNull(iter.next());
+            secondChildrenCount++;
+        }
+        assertEquals("children count must reduce from 1",
+                     firstChildrenCount - 1,
+                     secondChildrenCount);
+
+    }
+
+    /** Test the element iterator */
+    public void testGetChildElements() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        Iterator iter = elt.getChildElements();
+        int counter = 0;
+        while (iter.hasNext()) {
+            counter ++;
+            Object o = iter.next();
+            assertNotNull("Must return not null objects!", o);
+            assertTrue("All these should be elements!",
+                       ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
+        }
+        assertEquals("This element should contain only two elements ", 2, counter);
+    }
+    
+    /** Test the element iterator */
+    public void testGetChildrenWithName() {
+        OMElement elt = getTestResourceAsElement(omMetaFactory, TestConstants.SOAP_SOAPMESSAGE1);
+        QName qname = new QName(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,
+                                SOAP11Constants.BODY_LOCAL_NAME);
+        Iterator iter = elt.getChildrenWithName(qname);
+        int counter = 0;
+        while (iter.hasNext()) {
+            counter ++;
+            Object o = iter.next();
+            assertNotNull("Must return not null objects!", o);
+            assertTrue("All these should be elements!",
+                       ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
+        }
+        assertEquals("This element should contain only one element with the given QName ", 1,
+                     counter);
+    }
+
     public void testSetText() {
         OMFactory factory = omMetaFactory.getOMFactory();
         String localName = "TestLocalName";

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java?rev=785435&r1=785434&r2=785435&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java Tue Jun 16 22:32:05 2009
@@ -19,162 +19,12 @@
 
 package org.apache.axiom.om;
 
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
-import org.apache.axiom.soap.SOAP11Constants;
-
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
 import java.util.Iterator;
 
 public class IteratorTest extends AbstractTestCase {
-    private OMElement envelope = null;
-
-    public IteratorTest(String testName) {
-        super(testName);
-    }
-
-    protected void setUp() throws Exception {
-        //lets use a plain OM factory
-        envelope =
-                new StAXOMBuilder(new OMLinkedListImplFactory(),
-                                  XMLInputFactory.newInstance().createXMLStreamReader(
-                                                  getTestResource(
-                                                          TestConstants.SOAP_SOAPMESSAGE1)))
-                        .getDocumentElement();
-    }
-
-    protected void tearDown() throws Exception {
-        envelope = null;
-    }
-
-    /** Test the plain iterator which includes all the children (including the texts) */
-    public void testIterator() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildren();
-        int counter = 0;
-        while (iter.hasNext()) {
-            counter ++;
-            assertNotNull("Must return not null objects!", iter.next());
-        }
-        assertEquals("This element should contain only five children including the text ", 5,
-                     counter);
-    }
-
-    /** Test the element iterator */
-    public void testElementIterator() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildElements();
-        int counter = 0;
-        while (iter.hasNext()) {
-            counter ++;
-            Object o = iter.next();
-            assertNotNull("Must return not null objects!", o);
-            assertTrue("All these should be elements!",
-                       ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
-        }
-        assertEquals("This element should contain only two elements ", 2, counter);
-    }
-
-    /** Test the element iterator */
-    public void testElementQNameIterator() {
-        OMElement elt = envelope;
-        QName qname = new QName(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI,
-                                SOAP11Constants.BODY_LOCAL_NAME);
-        Iterator iter = elt.getChildrenWithName(qname);
-        int counter = 0;
-        while (iter.hasNext()) {
-            counter ++;
-            Object o = iter.next();
-            assertNotNull("Must return not null objects!", o);
-            assertTrue("All these should be elements!",
-                       ((OMNode) o).getType() == OMNode.ELEMENT_NODE);
-        }
-        assertEquals("This element should contain only one element with the given QName ", 1,
-                     counter);
-    }
-
-    /** test the remove exception behavior */
-    public void testIteratorRemove1() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildren();
-
-        //this is supposed to throw an illegal state exception
-        try {
-            iter.remove();
-            fail("remove should throw an exception");
-        } catch (IllegalStateException e) {
-            //ok. this is what should happen
-        }
-
-    }
-
-    /** test the remove exception behavior, consecutive remove calls */
-    public void testIteratorRemove2() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildren();
-        if (iter.hasNext()) {
-            iter.next();
-        }
-        iter.remove();
-
-        //this call must generate an exception
-        try {
-            iter.remove();
-            fail("calling remove twice without a call to next is prohibited");
-        } catch (IllegalStateException e) {
-            //ok if we come here :)
-        }
-
-    }
-
-    /** Remove all! */
-    public void testIteratorRemove3() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildren();
-        while (iter.hasNext()) {
-            iter.next();
-            iter.remove();
-        }
-        iter = elt.getChildren();
-        if (iter.hasNext()) {
-            //we shouldn't reach here!
-            fail("No children should remain after removing all!");
-        }
-
-
-    }
-
-    /** test whether the children count reduces. */
-    public void testIteratorRemove4() {
-        OMElement elt = envelope;
-        Iterator iter = elt.getChildren();
-        int firstChildrenCount = 0;
-        int secondChildrenCount = 0;
-        while (iter.hasNext()) {
-            assertNotNull(iter.next());
-            firstChildrenCount++;
-        }
-
-        //remove the last node
-        iter.remove();
-
-        //reloop and check the count
-        //Note- here we should get a fresh iterator since there is no method to
-        //reset the iterator
-        iter = elt.getChildren(); //reset the iterator
-        while (iter.hasNext()) {
-            assertNotNull(iter.next());
-            secondChildrenCount++;
-        }
-        assertEquals("children count must reduce from 1",
-                     firstChildrenCount - 1,
-                     secondChildrenCount);
-
-    }
-
     /** This will test the errrors mentioned in @link http://issues.apache.org/jira/browse/WSCOMMONS-12 */
     public void testScenariosInJIRA() throws Exception {
         OMElement mtomSampleElement = createSampleXMLForTesting();