You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/06/19 16:03:16 UTC

svn commit: r548731 - in /incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests: general/XMLHelperTest.java util/XMLDifferenceException.java util/XMLEqualityChecker.java

Author: kelvingoodson
Date: Tue Jun 19 07:03:15 2007
New Revision: 548731

URL: http://svn.apache.org/viewvc?view=rev&rev=548731
Log:
TUSCANY-1351 applying Andy's fix as he hasn't been granted his committer rights yet :(

Added:
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java   (with props)
Modified:
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
    incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java

Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java?view=diff&rev=548731&r1=548730&r2=548731
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/general/XMLHelperTest.java Tue Jun 19 07:03:15 2007
@@ -19,36 +19,18 @@
  */
 package test.sdo21.tests.general;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.net.URL;
-
+import commonj.sdo.*;
+import commonj.sdo.helper.*;
 import org.junit.After;
+import static org.junit.Assert.*;
 import org.junit.Before;
 import org.junit.Test;
-
 import test.sdo21.framework.CTSTestCase;
 import test.sdo21.tests.util.XMLEqualityChecker;
 
-import commonj.sdo.ChangeSummary;
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Sequence;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
+import java.io.*;
+import java.math.BigDecimal;
+import java.net.URL;
 
 /**
  * Tests various concepts against the XMLHelper, including ...
@@ -132,8 +114,15 @@
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         getScope().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);
 
-        assertTrue("XMLHelper did not accurately reflect the ChangeSummary.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA_BEFORE_UNDO)));
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(TEST_DATA_BEFORE_UNDO)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect the ChangeSummary: " + e.getMessage());
+        }
 
         // Undo all changes and then serialize the resulting data graph again
 
@@ -142,8 +131,15 @@
         baos = new ByteArrayOutputStream();
         getScope().getXMLHelper().save(quote, TEST_NAMESPACE, "stockQuote", baos);
 
-        assertTrue("XMLHelper did not accurately reflect the ChangeSummary after undoChanges().", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA_AFTER_UNDO)));
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(TEST_DATA_AFTER_UNDO)
+            );
+        }
+        catch (Exception e) {
+            fail( "XMLHelper did not accurately reflect the ChangeSummary after undoChanges(): " + e.getMessage() );
+        }
     }
 
     /**
@@ -181,6 +177,8 @@
         Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
         DataObject quote = dataFactory.create(quoteType);
 
+        assertNotNull( quote );
+
         quote.setString("symbol", "s1");
 
         Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
@@ -212,8 +210,15 @@
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);
 
-        assertTrue("XMLHelper.save() did not accurately reflect open content.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(TEST_DATA)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect open content." + e.getMessage());
+        }
 
         // validate existing property condition
         Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
@@ -256,6 +261,7 @@
         XMLHelper xmlHelper = getScope().getXMLHelper();
 
         Type intType = types.getType("commonj.sdo", "Int");
+      assertNotNull( intType );
         Type stringType = types.getType("commonj.sdo", "String");
 
         // create a new Type for Customers
@@ -319,13 +325,30 @@
 
         baos = new ByteArrayOutputStream();
         xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);
-        assertTrue("XMLHelper.save() did not accurately reflect customer1.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER1_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(CUSTOMER1_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect customer1: " + e.getMessage());
+        }
 
         baos = new ByteArrayOutputStream();
         xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);
-        assertTrue("XMLHelper.save() did not accurately reflect customer2.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER2_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(CUSTOMER2_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect customer2: " + e.getMessage());
+        }
+
     }
 
     /**
@@ -397,13 +420,29 @@
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         xmlHelper.save(customer1, "http://example.com/customer", "Customer", baos);
-        assertTrue("XMLhelper.save() did not accurately reflect customer1", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER1_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(CUSTOMER1_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect customer1: " + e.getMessage());
+        }
 
         baos = new ByteArrayOutputStream();
         xmlHelper.save(customer2, "http://example.com/customer", "Customer", baos);
-        assertTrue("XMLhelper.save() did not accurately reflect customer2", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(CUSTOMER2_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(CUSTOMER2_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect customer2: " + e.getMessage());
+        }
     }
 
     /**
@@ -477,8 +516,16 @@
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote", baos);
-        assertTrue("XMLHelper.save() did not accurately reflect quote.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(MIXED_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect quote: " + e.getMessage());
+        }
     }
 
     /**
@@ -567,8 +614,16 @@
 
         FileOutputStream fos = new FileOutputStream("XMLTCOutput");
         xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", fos);
-        assertTrue("XMLHelper.save() did not accurately reflect quote.", XMLEqualityChecker
-            .equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXEDOPEN_XML)));
+
+        try {
+            XMLEqualityChecker.compareXmlFiles(
+                    new ByteArrayInputStream(baos.toByteArray()),
+                    getClass().getResource(MIXEDOPEN_XML)
+            );
+        }
+        catch (Exception e) {
+            fail("XMLHelper did not accurately reflect quote: " + e.getMessage());
+        }
     }
     
     @Before

Added: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java?view=auto&rev=548731
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java (added)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java Tue Jun 19 07:03:15 2007
@@ -0,0 +1,35 @@
+/**
+ *
+ *  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 test.sdo21.tests.util;
+
+public class XMLDifferenceException extends Exception {
+
+    public XMLDifferenceException(String message) {
+        super(message);
+    }
+
+    public XMLDifferenceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public XMLDifferenceException(String difference, Object value1, Object value2) {
+        super( difference + ": " + value1 + " versus " + value2 );
+    }
+}

Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLDifferenceException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java?view=diff&rev=548731&r1=548730&r2=548731
==============================================================================
--- incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java (original)
+++ incubator/tuscany/java/cts/sdo2.1/src/main/java/test/sdo21/tests/util/XMLEqualityChecker.java Tue Jun 19 07:03:15 2007
@@ -42,6 +42,9 @@
  * expected XML file.
  */
 public class XMLEqualityChecker {
+
+    private static final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance";
+
     /**
      * Places the nodes in nodeList into a indexed list.
      * 
@@ -61,115 +64,127 @@
     }
 
     /**
-     * Returns true if the two input NamedNodeMaps are equivalent, false
-     * otherwise.
-     * 
+     * Compares two NamedNodeMap instances and throws an exception if they are not equivalent.
+     *
      * @param mapA
      * @param mapB
      */
-    private static boolean equalNamedNodeMap(NamedNodeMap mapA, NamedNodeMap mapB) {
+    private static void compareNamedNodeMap(NamedNodeMap mapA, NamedNodeMap mapB) throws XMLDifferenceException {
         if (mapA == null) {
             if (mapB == null) {
-                return true;
+                return;
             }
-            return false;
+            throw new XMLDifferenceException( "mapA was null, mapB wasn't" );
         }
         if (mapA.getLength() != mapB.getLength()) {
-            return false;
+            throw new XMLDifferenceException( "map length", mapA.getLength(), mapB.getLength() );
         }
         for (int i = 0; i < mapA.getLength(); i++) {
             Node trialNode = mapA.item(i);
             if (trialNode == null) {
-                return false;
+                throw new XMLDifferenceException("mapB did not contain value at index " + i);
+            }
+            if (trialNode.getNodeName().startsWith("xmlns:")) {
+                // ignore namespace declarations since these will be checked on each element
+                // using the namespace
+                continue;
             }
             Node checkNode = mapB.getNamedItem(trialNode.getNodeName());
             if (checkNode == null) {
-                return false;
-            }
-            if (!equalNode(trialNode, checkNode)) {
-                return false;
+                throw new XMLDifferenceException("mapB did not contain value named '" + trialNode.getNodeName() + "'");
             }
+            compareNode(trialNode, checkNode);
         }
-        return true;
     }
 
     /**
-     * Returns true of the two Nodes are equivalent, false otherwise.
-     * 
+     * Compares two Node instances and throws an exception if they are not equivalent.
+     *
      * @param nodeA
      * @param nodeB
      */
-    private static boolean equalNode(Node nodeA, Node nodeB) {
+    private static void compareNode(Node nodeA, Node nodeB) throws XMLDifferenceException {
         if (nodeA == null) {
             if (nodeB == null) {
-                return true;
+                return;
             }
-            return false;
+            throw new XMLDifferenceException( "nodeA was null, nodeB wasn't" );
         }
         // following is intended to provide same function as 1.5 isEqualNode()
         if (nodeA.getNodeType() != nodeB.getNodeType()) {
-            return false;
-        }
-        if (!equalString(nodeA.getNodeName(), nodeB.getNodeName())) {
-            return false;
+            throw new XMLDifferenceException( "node type", nodeA.getNodeType(), nodeB.getNodeType() );
         }
         if (!equalString(nodeA.getLocalName(), nodeB.getLocalName())) {
-            return false;
-        }
-        if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) {
-            return false;
+            throw new XMLDifferenceException( "local name", nodeA.getLocalName(), nodeB.getLocalName() );
         }
         if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) {
-            return false;
-        }
-        if (!equalString(nodeA.getPrefix(), nodeB.getPrefix())) {
-            return false;
-        }
-        if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) {
-            return false;
-        }
-        if (!equalNamedNodeMap(nodeA.getAttributes(), nodeB.getAttributes())) {
-            return false;
-        }
-        if (!equalNodeList(nodeA.getChildNodes(), nodeB.getChildNodes())) {
-            return false;
+            throw new XMLDifferenceException( "namespace URI", nodeA.getNamespaceURI(), nodeB.getNamespaceURI() );
         }
-        if (nodeA.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
-            DocumentType documentTypeA = (DocumentType)nodeA;
-            DocumentType documentTypeB = (DocumentType)nodeB;
-            if (!equalString(documentTypeA.getPublicId(), documentTypeB.getPublicId())) {
-                return false;
-            }
-            if (!equalString(documentTypeA.getSystemId(), documentTypeB.getSystemId())) {
-                return false;
-            }
-            if (!equalString(documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset())) {
-                return false;
-            }
-            if (!equalNamedNodeMap(documentTypeA.getEntities(), documentTypeB.getEntities())) {
-                return false;
-            }
-            if (!equalNamedNodeMap(documentTypeA.getNotations(), documentTypeB.getNotations())) {
-                return false;
+
+        // special handling for xsi:type
+        if (XSI_NAMESPACE_URI.equals(nodeA.getNamespaceURI())
+            && nodeA.getLocalName().equals("type")) {
+
+            // because the gold xml file might use a different namespace prefix
+            // than the sdo implementation under test, we need to ignore the
+            // prefix used in any xsi:type attribute
+
+            String nodeValueA = nodeA.getNodeValue();
+            String nodeValueB = nodeB.getNodeValue();
+
+            int posA = nodeValueA.indexOf(':');
+            int posB = nodeValueB.indexOf(':');
+
+            if (posA != -1 && posB != -1 && nodeValueA.substring(posA+1).equals(nodeValueB.substring(posB+1))) {
+                // the type name does match
+            }
+            else {
+                if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) {
+                    throw new XMLDifferenceException ("node value", nodeA.getNodeValue(), nodeB.getNodeValue() );
+                }
+            }
+        }
+        else {
+            if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) {
+                throw new XMLDifferenceException(
+                        "value of node '" + nodeA.getLocalName() + "' in namespace '" + nodeA.getNamespaceURI() + "'", 
+                        nodeA.getNodeValue(), nodeB.getNodeValue() );
+            }
+
+            compareNamedNodeMap(nodeA.getAttributes(), nodeB.getAttributes());
+            compareNodeList( nodeA.getChildNodes(), nodeB.getChildNodes());
+            if (nodeA.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
+                DocumentType documentTypeA = (DocumentType)nodeA;
+                DocumentType documentTypeB = (DocumentType)nodeB;
+                if (!equalString(documentTypeA.getPublicId(), documentTypeB.getPublicId())) {
+                    throw new XMLDifferenceException( "public ID", documentTypeA.getPublicId(), documentTypeB.getPublicId() );
+                }
+                if (!equalString(documentTypeA.getSystemId(), documentTypeB.getSystemId())) {
+                    throw new XMLDifferenceException( "system ID", documentTypeA.getSystemId(), documentTypeB.getSystemId() );
+                }
+                if (!equalString(documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset())) {
+                    throw new XMLDifferenceException( "internal subset", documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset() );
+                }
+                compareNamedNodeMap(documentTypeA.getEntities(), documentTypeB.getEntities());
+                compareNamedNodeMap(documentTypeA.getNotations(), documentTypeB.getNotations());
             }
         }
-        return true;
     }
 
     /**
-     * Returns true of the two NodeLists are equivalent, false otherwise.
+     * Compares two NodeList instances and throws an exception if they are not equivalent.
      * 
      * @param nodeListA
      * @param nodeListB
      */
-    private static boolean equalNodeList(NodeList nodeListA, NodeList nodeListB) {
+    private static void compareNodeList(NodeList nodeListA, NodeList nodeListB) throws XMLDifferenceException {
         if (nodeListA == null) {
             if (nodeListB == null) {
-                return true;
+                return;
             }
-            return false;
+            throw new XMLDifferenceException( "nodeListA was null, nodeListB wasn't" );
         }
-        return equalNodes(nodeListA, nodeListB);
+        compareNodes(nodeListA, nodeListB);
     }
 
     /**
@@ -189,12 +204,14 @@
     }
 
     /**
-     * Returns true of the two NodeListss are equivalent, false otherwise.
+     * Returns true if the two NodeLists are equivalent, false otherwise.
      * 
-     * @param nodeListA
-     * @param nodeListB
+     * @param sourceNodeList
+     * @param targetNodeList
      */
-    private static boolean equalNodes(NodeList sourceNodeList, NodeList targetNodeList) {
+    private static void compareNodes(NodeList sourceNodeList, NodeList targetNodeList)
+        throws XMLDifferenceException {
+
         ArrayList sourceNodes = new ArrayList();
         ArrayList targetNodes = new ArrayList();
 
@@ -204,97 +221,85 @@
         int sourceLength = sourceNodes.size();
         int targetLength = targetNodes.size();
 
-        if (sourceLength != targetLength)
-            return false;
+        if (sourceLength != targetLength) {
+            throw new XMLDifferenceException(
+                    "node count",
+                    sourceLength,
+                    targetLength
+            );
+        }
 
         for (int i = 0; i < sourceLength; i++) {
             Node sourceNode = (Node)sourceNodes.get(i);
             Node targetNode = (Node)targetNodes.get(i);
 
-            /*
-             * remove comment when migrated to Java 1.5 if
-             * (!sourceNode.isEqualNode(targetNode)) return false;
-             */
-            // following is intended as 1.4 equivalent of isEqualNode()
-            if (!equalNode(sourceNode, targetNode))
-                return false;
+            compareNode(sourceNode, targetNode);
         } // for
-
-        return true;
     }
 
     /**
-     * Returns true of the two XML files are equivalent, false otherwise.
+     * Throws exception if the two XML files are not equivalent.
      * Accepts as input two URLs which identify the XML files, and calls
      * equalXMLFiles(InputStream, InputStream).
      * 
      * @param source
      * @param target
      */
-    public static boolean equalXmlFiles(URL source, URL target) {
-        try {
-            return equalXmlFiles(source.openStream(), target.openStream());
-        } catch (IOException e) {
-            return false;
-        }
+    public static void compareXmlFiles(URL source, URL target)
+        throws XMLDifferenceException, IOException {
+        compareXmlFiles(source.openStream(), target.openStream());
     }
 
     /**
-     * Returns true of the two XML files are equivalent, false otherwise.
+     * Throws exception if the two XML files are not equivalent.
      * Accepts as input an InputStream and a URL which identify the XML files,
      * and calls equalXMLFiles(InputStream, InputStream).
      * 
      * @param sourceStream
      * @param target
      */
-    public static boolean equalXmlFiles(InputStream sourceStream, URL target) {
-        try {
-            return equalXmlFiles(sourceStream, target.openStream());
-        } catch (IOException e) {
-            return false;
-        }
+    public static void compareXmlFiles(InputStream sourceStream, URL target)
+        throws XMLDifferenceException, IOException {
+        compareXmlFiles(sourceStream, target.openStream());
     }
 
     /**
-     * Returns true of the two XML files are equivalent, false otherwise.
+     * Throws exception if the two XML files are not equivalent.
      * Accepts as input a URL and an InputStream which identify the XML files,
      * and calls equalXMLFiles(InputStream, InputStream).
      * 
      * @param source
      * @param targetStream
      */
-    public static boolean equalXmlFiles(URL source, InputStream targetStream) {
-        try {
-            return equalXmlFiles(source.openStream(), targetStream);
-        } catch (IOException e) {
-            return false;
-        }
+    public static void compareXmlFiles(URL source, InputStream targetStream)
+        throws XMLDifferenceException, IOException {
+        compareXmlFiles(source.openStream(), targetStream);
     }
 
     /**
-     * Returns true of the two XML files are equivalent, false otherwise.
+     * Throws exception if the two XML files are not equivalent.
      * Accepts as input two InputStreams which identify the XML files.
      * 
      * @param sourceStream
      * @param targetStream
      */
-    public static boolean equalXmlFiles(InputStream sourceStream, InputStream targetStream) {
+    public static void compareXmlFiles(InputStream sourceStream, InputStream targetStream)
+        throws XMLDifferenceException, IOException {
+
         DocumentBuilder builder;
         Document sourceDocument;
         Document targetDocument;
 
         try {
-            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setNamespaceAware(true);
+            builder = factory.newDocumentBuilder();
             sourceDocument = builder.parse(sourceStream);
             targetDocument = builder.parse(targetStream);
-        } catch (FactoryConfigurationError fce) {
-            return false;
-        } catch (ParserConfigurationException ce) {
-            return false;
-        } catch (SAXException se) {
-            return false;
         } catch (IOException ie) {
-            return false;
+            throw ie;
+        } catch (Exception e) {
+            throw new XMLDifferenceException( "Failed to parse files", e );
         }
 
         sourceDocument.normalize();
@@ -314,6 +319,6 @@
         NodeList sourceNodes = sourceDocument.getChildNodes();
         NodeList targetNodes = targetDocument.getChildNodes();
 
-        return equalNodes(sourceNodes, targetNodes);
+        compareNodes(sourceNodes, targetNodes);
     }
 }



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