ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1044929 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/m...
Date Sun, 12 Dec 2010 21:18:56 GMT
Author: veithen
Date: Sun Dec 12 21:18:55 2010
New Revision: 1044929

URL: http://svn.apache.org/viewvc?rev=1044929&view=rev
Log:
Clarified the specification of the OMElement#setText(QName) method and refactored the corresponding
test case. Note that DOOM doesn't support this method.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQName.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/ImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.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=1044929&r1=1044928&r2=1044929&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 Dec 12 21:18:55 2010
@@ -411,7 +411,14 @@ public interface OMElement extends OMNod
     /** @param text  */
     void setText(String text);
 
-    void setText(QName text);
+    /**
+     * Set the content of this element to the given QName. If no matching namespace declaration
for
+     * the QName is in scope, then this method will add one.
+     * 
+     * @param qname
+     *            the QName value
+     */
+    void setText(QName qname);
 
     /**
      * Returns the non-empty text children as a string.

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java?rev=1044929&r1=1044928&r2=1044929&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ImplementationTest.java
Sun Dec 12 21:18:55 2010
@@ -23,9 +23,13 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.AxiomTestSuiteBuilder;
+import org.apache.axiom.ts.om.element.TestSetTextQName;
 
 public class ImplementationTest extends TestCase {
     public static TestSuite suite() {
-        return AxiomTestSuiteBuilder.suite(new OMDOMMetaFactory());
+        AxiomTestSuiteBuilder builder = new AxiomTestSuiteBuilder(new OMDOMMetaFactory());
+        // OMElement#setText(QName) is unsupported
+        builder.exclude(TestSetTextQName.class);
+        return builder.build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ImplementationTest.java?rev=1044929&r1=1044928&r2=1044929&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ImplementationTest.java
Sun Dec 12 21:18:55 2010
@@ -26,6 +26,6 @@ import junit.framework.TestSuite;
 
 public class ImplementationTest extends TestCase {
     public static TestSuite suite() {
-        return AxiomTestSuiteBuilder.suite(new OMLinkedListMetaFactory());
+        return new AxiomTestSuiteBuilder(new OMLinkedListMetaFactory()).build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java?rev=1044929&r1=1044928&r2=1044929&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMElementTest.java
Sun Dec 12 21:18:55 2010
@@ -19,49 +19,20 @@
 
 package org.apache.axiom.om.impl.llom;
 
-import java.util.Iterator;
-
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMElementTestBase;
 import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
 
 public class OMElementTest extends OMElementTestBase {
-    private static final String AXIS2_NS_URI = "http://ws.apache.org/axis2";
-    private static final String AXIS2_NS_PREFIX = "axis2";
     private static final String SOME_TEXT = "Some Text";
     
     public OMElementTest() {
         super(new OMLinkedListMetaFactory());
     }
 
-    public void testTextQNames() {
-        OMFactory factory = omMetaFactory.getOMFactory();
-        OMElement omElement = factory.createOMElement("TestElement", null);
-        omElement.setText(new QName(AXIS2_NS_URI, SOME_TEXT, AXIS2_NS_PREFIX));
-
-        Iterator allDeclaredNamespaces = omElement.getAllDeclaredNamespaces();
-        boolean foundNamespace = false;
-        while (allDeclaredNamespaces.hasNext()) {
-            OMNamespace omNamespace = (OMNamespace) allDeclaredNamespaces.next();
-            if (AXIS2_NS_URI.equals(omNamespace.getNamespaceURI()) &&
-                    AXIS2_NS_PREFIX.equals(omNamespace.getPrefix())) {
-                foundNamespace = true;
-            }
-        }
-        assertTrue("Namespace of the text is not defined in the parent element", foundNamespace);
-
-        String elementString = omElement.toString();
-        assertTrue(elementString.indexOf(AXIS2_NS_PREFIX + ":" + SOME_TEXT) > -1);
-        assertTrue((AXIS2_NS_PREFIX + ":" + SOME_TEXT).equals(omElement.getText()));
-
-        QName textAsQName = omElement.getTextAsQName();
-        assertTrue(textAsQName.equals(new QName(AXIS2_NS_URI, SOME_TEXT, AXIS2_NS_PREFIX)));
-    }
-
     public void testTextQNamesWithoutQNames() {
         OMFactory factory = omMetaFactory.getOMFactory();
         OMElement omElement = factory.createOMElement("TestElement", null);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java?rev=1044929&r1=1044928&r2=1044929&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
Sun Dec 12 21:18:55 2010
@@ -18,17 +18,39 @@
  */
 package org.apache.axiom.ts;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.axiom.om.OMMetaFactory;
 
 import junit.framework.TestSuite;
 
 public class AxiomTestSuiteBuilder {
-    public static TestSuite suite(OMMetaFactory metaFactory) {
-        TestSuite suite = new TestSuite();
-        suite.addTest(new org.apache.axiom.ts.om.element.TestGetAttributeValueWithXmlPrefix1(metaFactory));
-        suite.addTest(new org.apache.axiom.ts.om.element.TestGetAttributeValueWithXmlPrefix2(metaFactory));
-        suite.addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix1(metaFactory));
-        suite.addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix2(metaFactory));
+    private final OMMetaFactory metaFactory;
+    private final Set/*<Class>*/ excludedTests = new HashSet();
+    private TestSuite suite;
+    
+    public AxiomTestSuiteBuilder(OMMetaFactory metaFactory) {
+        this.metaFactory = metaFactory;
+    }
+    
+    public void exclude(Class testClass) {
+        excludedTests.add(testClass);
+    }
+    
+    public TestSuite build() {
+        suite = new TestSuite();
+        addTest(new org.apache.axiom.ts.om.element.TestGetAttributeValueWithXmlPrefix1(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetAttributeValueWithXmlPrefix2(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix1(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix2(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));
         return suite;
     }
+    
+    private void addTest(AxiomTestCase test) {
+        if (!excludedTests.contains(test.getClass())) {
+            suite.addTest(test);
+        }
+    }
 }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQName.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQName.java?rev=1044929&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQName.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetTextQName.java
Sun Dec 12 21:18:55 2010
@@ -0,0 +1,58 @@
+/*
+ * 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#setText(QName)}, in particular that it adds a
+ * namespace declaration if necessary.
+ */
+public class TestSetTextQName extends AxiomTestCase {
+    public TestSetTextQName(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement("TestElement", null);
+        QName qname = new QName("urn:ns1", "test", "ns");
+        element.setText(qname);
+        boolean foundNamespace = false;
+        for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
+            OMNamespace ns = (OMNamespace)it.next();
+            if ("urn:ns1".equals(ns.getNamespaceURI()) && "ns".equals(ns.getPrefix()))
{
+                foundNamespace = true;
+            }
+        }
+        assertTrue("Namespace of the text is not defined in the parent element", foundNamespace);
+
+        assertTrue(element.toString().contains("ns:test"));
+        assertEquals("ns:test", element.getText());
+        assertEquals(qname, element.getTextAsQName());
+    }
+}

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



Mime
View raw message