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 ch...@apache.org on 2006/12/10 18:38:21 UTC

svn commit: r485228 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java

Author: chinthaka
Date: Sun Dec 10 09:38:20 2006
New Revision: 485228

URL: http://svn.apache.org/viewvc?view=rev&rev=485228
Log:
- Adding one more test case contributed by Sameera Madhushan.
- small re-factoring of the code.


Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?view=diff&rev=485228&r1=485227&r2=485228
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Sun Dec 10 09:38:20 2006
@@ -523,9 +523,11 @@
                                     OMNamespace ns) {
         OMNamespace namespace = null;
         if (ns != null) {
-            namespace = findNamespace(ns.getNamespaceURI(), ns.getPrefix());
+            String namespaceURI = ns.getNamespaceURI();
+            String prefix = ns.getPrefix();
+            namespace = findNamespace(namespaceURI, prefix);
             if (namespace == null) {
-                namespace = new OMNamespaceImpl(ns.getNamespaceURI(), ns.getPrefix());
+                namespace = new OMNamespaceImpl(namespaceURI, prefix);
             }
         }
         return addAttribute(new OMAttributeImpl(attributeName, namespace, value, this.factory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java?view=auto&rev=485228
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMAttributeTest.java Sun Dec 10 09:38:20 2006
@@ -0,0 +1,89 @@
+package org.apache.axiom.om.impl.llom;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.*;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.ByteArrayInputStream;
+
+public class OMAttributeTest extends TestCase {
+
+    public void testAddAttribute() {
+        String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header name = \"jhon\"/><soapenv:Body><my:uploadFileUsingMTOM xmlns:my=\"http://localhost/my\"><my:folderName>/home/saliya/Desktop</my:folderName></my:uploadFileUsingMTOM></soapenv:Body><Body>TTTT</Body> </soapenv:Envelope>";
+
+
+        String test1 = "";
+        String test2 = "";
+
+        test1 = addAttributeMethod1(xmlString);
+        test2 = addAttributeMethod2(xmlString);
+
+        assertEquals(test1, test2);
+    }
+
+    private String addAttributeMethod1(String xmlString) {
+        XMLStreamReader parser2;
+
+        try {
+            parser2 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
+            StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
+            OMElement doc = builder2.getDocumentElement();
+
+            OMFactory factory = OMAbstractFactory.getOMFactory();
+            OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
+
+
+            //code line to be tested
+            OMAttribute at = factory.createOMAttribute("id", ns, "value");
+            doc.addAttribute(at);
+
+            return doc.toString();
+
+        } catch (Exception e) {
+            return "ERROR";
+            //e.printStackTrace();
+        }
+
+    }
+
+    private String addAttributeMethod2(String xmlString) {
+        XMLStreamReader parser2;
+
+        try {
+            parser2 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
+            StAXOMBuilder builder2 = new StAXOMBuilder(parser2);
+            OMElement doc = builder2.getDocumentElement();
+
+            OMFactory factory = OMAbstractFactory.getOMFactory();
+            OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
+
+            //code line to be tested
+            doc.addAttribute("id", "value", ns);
+
+            return doc.toString();
+
+        } catch (Exception e) {
+            return "ERROR";
+            //e.printStackTrace();
+        }
+
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org