Author: veithen
Date: Mon Jul 18 18:12:40 2011
New Revision: 1147991
URL: http://svn.apache.org/viewvc?rev=1147991&view=rev
Log:
Added test cases for OMElement#setNamespace.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.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/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/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=1147991&r1=1147990&r2=1147991&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
Mon Jul 18 18:12:40 2011
@@ -355,11 +355,13 @@ public interface OMElement extends OMNod
String getNamespaceURI();
/**
- * Sets the Namespace. This will first search for a namespace in the
current scope with the
- * given namespace. If no namespace is found with the given details, then
it will declare a new
- * one. Then that namespace will be assigned to this element.
- *
+ * Set the namespace for this element. In addition to changing the
namespace URI and prefix of
+ * the element information item, this method ensures that a corresponding
namespace declaration
+ * exists. If no corresponding namespace declaration is already in scope,
then a new one will be
+ * added to this element.
+ *
* @param namespace
+ * the new namespace for this element
*/
void setNamespace(OMNamespace namespace);
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=1147991&r1=1147990&r2=1147991&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
Mon Jul 18 18:12:40 2011
@@ -28,6 +28,7 @@ import org.apache.axiom.ts.om.container.
import org.apache.axiom.ts.om.element.TestGetChildrenWithName4;
import
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement;
import
org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
+import org.apache.axiom.ts.om.element.TestSetNamespace;
import org.apache.axiom.ts.om.element.TestSetTextQName;
import org.apache.axiom.ts.om.factory.TestCreateOMElementWithGeneratedPrefix;
import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
@@ -75,6 +76,7 @@ public class OMImplementationTest extend
// TODO: investigate why this is not working with DOOM
builder.exclude(TestGetChildrenWithName4.class);
+ builder.exclude(TestSetNamespace.class);
return builder.build();
}
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=1147991&r1=1147990&r2=1147991&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
Mon Jul 18 18:12:40 2011
@@ -150,6 +150,8 @@ public class OMTestSuiteBuilder extends
"<person><name xmlns=\"urn:ns\">John</name><age
xmlns=\"urn:ns\">34</age><weight xmlns=\"urn:ns\">50</weight></person>"));
addTest(new
org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestSetNamespace(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestSetNamespaceWithMatchingBindingInScope(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSetText(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
for (int i=0; i<OMElementCreator.INSTANCES.length; i++) {
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java?rev=1147991&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java
Mon Jul 18 18:12:40 2011
@@ -0,0 +1,52 @@
+/*
+ * 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 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.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setNamespace(OMNamespace)} if no
matching namespace
+ * binding is in scope. In this case, the method must add a new namespace
declaration.
+ */
+public class TestSetNamespace extends AxiomTestCase {
+ public TestSetNamespace(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement element = factory.createOMElement(new QName("test"));
+ OMNamespace ns = factory.createOMNamespace("urn:test", "p");
+ element.setNamespace(ns);
+ assertEquals(new QName("urn:test", "test"), element.getQName());
+ assertEquals(ns, element.getNamespace());
+ Iterator it = element.getAllDeclaredNamespaces();
+ assertTrue(it.hasNext());
+ assertEquals(ns, it.next());
+ assertFalse(it.hasNext());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespace.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.java?rev=1147991&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.java
Mon Jul 18 18:12:40 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setNamespace(OMNamespace)} if a
matching namespace binding
+ * is in scope. In this case, no new namespace declaration is added.
+ */
+public class TestSetNamespaceWithMatchingBindingInScope extends AxiomTestCase {
+ public TestSetNamespaceWithMatchingBindingInScope(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("urn:test", "p");
+ OMElement parent = factory.createOMElement("parent", ns);
+ OMElement child = factory.createOMElement("child", null, parent);
+ child.setNamespace(ns);
+ assertEquals(new QName("urn:test", "child"), child.getQName());
+ assertEquals(ns, child.getNamespace());
+ assertFalse(child.getAllDeclaredNamespaces().hasNext());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceWithMatchingBindingInScope.java
------------------------------------------------------------------------------
svn:eol-style = native