Author: veithen
Date: Fri Feb  7 18:52:56 2014
New Revision: 1565762

URL: http://svn.apache.org/r1565762
Log:
Fixed an issue with the Iterator returned by 
OMElement#getAllDeclaredNamespaces() in DOOM.

Added:
    
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetAllDeclaredNamespacesNoSuchElementException.java
   (with props)
Modified:
    
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
    
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java?rev=1565762&r1=1565761&r2=1565762&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
 Fri Feb  7 18:52:56 2014
@@ -19,6 +19,7 @@
 package org.apache.axiom.om.impl.dom;
 
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 import javax.xml.XMLConstants;
 
@@ -58,6 +59,9 @@ class NSDeclIterator implements Iterator
     public Object next() {
         hasNext();
         hasNextCalled = false;
+        if (nsDecl == null) {
+            throw new NoSuchElementException();
+        }
         return new OMNamespaceImpl(nsDecl.getValue(), nsDecl.getPrefix() == 
null ? "" : nsDecl.getLocalName());
     }
 

Modified: 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1565762&r1=1565761&r2=1565762&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
 Fri Feb  7 18:52:56 2014
@@ -245,6 +245,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAllAttributes1(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAllAttributes2(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespaces(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespacesNoSuchElementException(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespacesRemove(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAttributeValueNonExisting(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestGetAttributeValueWithXmlPrefix1(metaFactory));

Added: 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetAllDeclaredNamespacesNoSuchElementException.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetAllDeclaredNamespacesNoSuchElementException.java?rev=1565762&view=auto
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetAllDeclaredNamespacesNoSuchElementException.java
 (added)
+++ 
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetAllDeclaredNamespacesNoSuchElementException.java
 Fri Feb  7 18:52:56 2014
@@ -0,0 +1,49 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the iterator returned by {@link 
OMElement#getAllDeclaredNamespaces()} respects the
+ * {@link Iterator} contract with respect to throwing {@link 
NoSuchElementException}.
+ */
+public class TestGetAllDeclaredNamespacesNoSuchElementException extends 
AxiomTestCase {
+    public TestGetAllDeclaredNamespacesNoSuchElementException(OMMetaFactory 
metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), 
"<e xmlns:p='urn:test' p:attr='test'/>");
+        Iterator it = element.getAllDeclaredNamespaces();
+        it.next();
+        try {
+            it.next();
+            fail("Expected NoSuchElementException");
+        } catch (NoSuchElementException ex) {
+            // Expected
+        }
+    }
+}

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


Reply via email to