ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r157675 - webservices/axis/trunk/java/modules/om/src/test-resources/soap webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util
Date Wed, 16 Mar 2005 04:52:36 GMT
Author: chinthaka
Date: Tue Mar 15 20:52:34 2005
New Revision: 157675

URL: http://svn.apache.org/viewcvs?view=rev&rev=157675
Log:
Adding OM level XML comparator

Added:
    webservices/axis/trunk/java/modules/om/src/test-resources/soap/OMElementTest.xml
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/OMElementTest.java
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparator.java
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparisonException.java

Added: webservices/axis/trunk/java/modules/om/src/test-resources/soap/OMElementTest.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test-resources/soap/OMElementTest.xml?view=auto&rev=157675
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test-resources/soap/OMElementTest.xml (added)
+++ webservices/axis/trunk/java/modules/om/src/test-resources/soap/OMElementTest.xml Tue Mar
15 20:52:34 2005
@@ -0,0 +1,22 @@
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                  xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
+    <soapenv:Header>
+        <wsa:MessageID soapenv:mustUnderstand="0">
+            uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
+        <wsa:To soapenv:mustUnderstand="0">
+            http://localhost:8081/axis/services/BankPort</wsa:To>
+        <wsa:From soapenv:mustUnderstand="0">
+            <Address xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">
+                http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous
+            </Address>
+        </wsa:From>
+    </soapenv:Header>
+    <soapenv:Body>
+        <axis2:echoVoid xmlns:axis2="http://ws.apache.org/axis2">This is some text
+            <axis2:input>2</axis2:input>
+            Some Other Text
+        </axis2:echoVoid>
+    </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file

Added: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/OMElementTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/OMElementTest.java?view=auto&rev=157675
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/OMElementTest.java
(added)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/OMElementTest.java
Tue Mar 15 20:52:34 2005
@@ -0,0 +1,52 @@
+package org.apache.axis.om;
+
+import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class OMElementTest extends OMTestCase implements OMConstants {
+    private static final String WSA_URI = "http://schemas.xmlsoap.org/ws/2004/03/addressing";
+    private static final String WSA_TO = "To";
+
+
+    public OMElementTest(String testName) {
+        super(testName);
+    }
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+
+    }
+
+    public void testGetText(){
+        try {
+            StAXSOAPModelBuilder soapBuilder = getOMBuilder("soap/OMElementTest.xml");
+            SOAPEnvelope soapEnvelope = (SOAPEnvelope) soapBuilder.getDocumentElement();
+            OMElement wsaTo = (OMElement) soapEnvelope.getHeader().getChildWithName(new QName(WSA_URI,
WSA_TO));
+
+            String expectedString = "http://localhost:8081/axis/services/BankPort";
+            assertEquals("getText is not returning the correct value", wsaTo.getText().trim(),
expectedString);
+        } catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
+
+}

Added: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparator.java?view=auto&rev=157675
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparator.java
(added)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparator.java
Tue Mar 15 20:52:34 2005
@@ -0,0 +1,126 @@
+package org.apache.axis.om.util;
+
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class XMLComparator {
+    /**
+     * Eran Chinthaka (chinthaka@apache.org)
+     */
+    private Log log = LogFactory.getLog(getClass());
+
+
+    public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException
{
+        if(elementOne == null && elementTwo == null){
+            log.info("Both Elements are null.");
+            return true;
+        }
+        if(elementOne == null && elementTwo != null){
+            throw new XMLComparisonException("Element One is null and Element Two is not
null");
+        }
+        if(elementOne != null && elementTwo == null){
+            throw new XMLComparisonException("Element Two is null and Element One is not
null");
+        }
+
+        log.info("Now Checking "+ elementOne.getLocalName() + " and " + elementTwo.getLocalName()
+ "=============================");
+
+        log.info("Comparing Element Names .......");
+        compare("Elements names are not equal. ", elementOne.getLocalName(), elementTwo.getLocalName());
+
+        log.info("Comparing Namespaces .........");
+        compare("Element namespaces are not equal", elementOne.getNamespace(), elementTwo.getNamespace());
+
+        log.info("Comparing attributes .....");
+        compareAllAttributes(elementOne, elementTwo);
+
+        log.info("Comparing texts .....");
+        compare("Elements texts are not equal ", elementOne.getText(), elementTwo.getText());
+
+        log.info("Comparing Children ......");
+        compareAllChildren(elementOne, elementTwo);
+
+
+        return true;
+    }
+
+    private void compareAllAttributes(OMElement elementOne, OMElement elementTwo) throws
XMLComparisonException {
+        compareAttibutes(elementOne, elementTwo);
+        compareAttibutes(elementTwo, elementOne);
+    }
+
+    private void compareAllChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException
{
+        compareChildren(elementOne, elementTwo);
+        compareChildren(elementTwo, elementOne);
+    }
+
+    private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException
{
+        Iterator elementOneChildren = elementOne.getChildren();
+        while (elementOneChildren.hasNext()) {
+            OMNode omNode = (OMNode) elementOneChildren.next();
+            if(omNode instanceof OMElement){
+                OMElement elementOneChild = (OMElement) omNode;
+                OMNode elementTwoChild = elementTwo.getChildWithName(elementOneChild.getQName());
+                if(elementTwoChild == null){
+                    throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName()
+ " element under " + elementTwo.getLocalName());
+                }
+                compare(elementOneChild, (OMElement) elementTwoChild);
+            }
+        }
+    }
+
+
+    private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException
{
+        Iterator attributes = elementOne.getAttributes();
+        while (attributes.hasNext()) {
+            OMAttribute omAttribute = (OMAttribute) attributes.next();
+            OMAttribute attr = elementTwo.getAttributeWithQName(omAttribute.getQName());
+            if(attr == null){
+                throw new XMLComparisonException("Attributes are not the same in two elements.
Attribute "+ omAttribute.getLocalName() + " != ");
+            }
+        }
+    }
+
+    private void compare(String failureNotice, String one, String two) throws XMLComparisonException
{
+        if(!one.equals(two)){
+            throw new XMLComparisonException(failureNotice+ one + " != " + two);
+        }
+    }
+
+    private void compare(String failureNotice, OMNamespace one, OMNamespace two) throws XMLComparisonException
{
+        if(one == null && two == null){
+            return;
+        }else if(one != null && two == null){
+            throw new XMLComparisonException("First Namespace is NOT null. But the second
is null");
+        }else if(one == null && two != null){
+            throw new XMLComparisonException("First Namespace is null. But the second is
NOT null");
+        }
+
+        if(!one.getName().equals(two.getName())){
+            throw new XMLComparisonException(failureNotice + one + " != " + two);
+        }
+
+        // Do we need to compare prefixes as well
+    }
+}

Added: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java?view=auto&rev=157675
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
(added)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparatorTest.java
Tue Mar 15 20:52:34 2005
@@ -0,0 +1,42 @@
+package org.apache.axis.om.util;
+
+import org.apache.axis.om.AbstractTestCase;
+import org.apache.axis.om.OMTestCase;
+import org.apache.axis.om.impl.llom.builder.StAXSOAPModelBuilder;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class XMLComparatorTest extends OMTestCase{
+    /**
+     * Eran Chinthaka (chinthaka@apache.org)
+     */
+    public XMLComparatorTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void testCompare() throws Exception {
+        StAXSOAPModelBuilder omBuilder = getOMBuilder("");
+        XMLComparator xmlComparator = new XMLComparator();
+        assertTrue(xmlComparator.compare(omBuilder.getDocumentElement(), omBuilder.getDocumentElement()));
+
+
+    }
+}

Added: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparisonException.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparisonException.java?view=auto&rev=157675
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparisonException.java
(added)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/util/XMLComparisonException.java
Tue Mar 15 20:52:34 2005
@@ -0,0 +1,35 @@
+package org.apache.axis.om.util;
+
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+public class XMLComparisonException extends Exception {
+    /**
+     * Eran Chinthaka (chinthaka@apache.org)
+     */
+   
+    public XMLComparisonException(String message) {
+        super(message);
+    }
+
+    public XMLComparisonException(Throwable cause) {
+        super(cause);
+    }
+
+    public XMLComparisonException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}



Mime
View raw message