Author: chinthaka
Date: Wed Jul 26 01:04:53 2006
New Revision: 425660

URL: http://svn.apache.org/viewvc?rev=425660&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/WSCOMMONS-40 with a test case. 
Thanks Chamikara for the test case, I got it from the issue you created in JIRA.

Added:
    webservices/commons/trunk/modules/axiom/test/org/apache/axiom/binary/
    
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/binary/fastinfoset/
    
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/xpath/XPathAppliedToSOAPEnvelopeTest.java
Modified:
    
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/xpath/DocumentNavigator.java

Modified: 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/xpath/DocumentNavigator.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/xpath/DocumentNavigator.java?rev=425660&r1=425659&r2=425660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/xpath/DocumentNavigator.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/xpath/DocumentNavigator.java
 Wed Jul 26 01:04:53 2006
@@ -600,7 +600,13 @@
         if (contextNode instanceof OMDocument) {
             return contextNode;
         }
-        return getDocumentNode(((OMNode) contextNode).getParent());
+        OMContainer parent = ((OMNode) contextNode).getParent();
+        if (parent == null) {
+            // this node doesn't have a parent Document. So return the 
document element itself
+            return contextNode;
+        } else {
+            return getDocumentNode(parent);
+        }
     }
 
     /**

Added: 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/xpath/XPathAppliedToSOAPEnvelopeTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/xpath/XPathAppliedToSOAPEnvelopeTest.java?rev=425660&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/xpath/XPathAppliedToSOAPEnvelopeTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/xpath/XPathAppliedToSOAPEnvelopeTest.java
 Wed Jul 26 01:04:53 2006
@@ -0,0 +1,73 @@
+package org.apache.axiom.xpath;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+/*
+ * 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.
+ */
+
+public class XPathAppliedToSOAPEnvelopeTest extends TestCase {
+
+    public void testDocumentNotAdded () throws Exception {
+               SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+
+               OMElement elem1 = factory.createOMElement("elem1",null);
+               OMElement elem2 = factory.createOMElement("elem2",null);
+               OMElement elem3 = factory.createOMElement("elem3",null);
+               elem2.addChild(elem3);
+               elem1.addChild(elem2);
+               SOAPEnvelope envelope = factory.getDefaultEnvelope();
+               envelope.getBody().addChild(elem1);
+
+               //The only difference of the two test methods is the following 
line.
+//             factory.createOMDocument().addChild(envelope);
+
+               String XPathString = "//elem1";
+
+               AXIOMXPath XPath = new AXIOMXPath (XPathString);
+               OMNode node = (OMNode) XPath.selectSingleNode(envelope);
+
+
+               assertNotNull(node);
+       }
+
+       public void testDocumentAdded () throws Exception {
+               SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+
+               OMElement elem1 = factory.createOMElement("elem1",null);
+               OMElement elem2 = factory.createOMElement("elem2",null);
+               OMElement elem3 = factory.createOMElement("elem3",null);
+               elem2.addChild(elem3);
+               elem1.addChild(elem2);
+               SOAPEnvelope envelope = factory.getDefaultEnvelope();
+               envelope.getBody().addChild(elem1);
+
+               //The only difference of the two test methods is the following 
line.
+               factory.createOMDocument().addChild(envelope);
+
+               String XPathString = "//elem1";
+
+               AXIOMXPath XPath = new AXIOMXPath (XPathString);
+               OMNode node = (OMNode) XPath.selectSingleNode(envelope);
+
+
+               assertNotNull(node);
+       }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to