--- old/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java 2014-10-28 09:57:50.000000000 -0700 +++ new/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java 2014-10-28 09:57:49.000000000 -0700 @@ -22,11 +22,15 @@ */ package jaxp.library; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import static org.testng.Assert.fail; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; /** * This is an interface provide basic support for JAXP functional test. @@ -60,13 +64,13 @@ /** * Compare contents of golden file with test output file line by line. - * return true if they're identical. + * return true if they're identical. * @param goldfile Golden output file name * @param outputfile Test output file name * @return true if two files are identical. * false if two files are not identical. - * @throws IOException if an I/O error occurs reading from the file or a - * malformed or unmappable byte sequence is read + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read */ public static boolean compareWithGold(String goldfile, String outputfile) throws IOException { @@ -75,8 +79,39 @@ } /** + * Compare contents of golden file with test output file by their document + * representation. + * Here we ignore the white space and comments. return true if they're + * lexical identical. + * @param goldfile Golden output file name. + * @param resultFile Test output file name. + * @return true if two file's document representation are identical. + * false if two file's document representation are not identical. + * @throws FactoryConfigurationError in case of service configuration error. + * or if the implementation is not available or cannot be instantiated. + * @throws SAXException If any parse errors occur. + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read . + */ + public static boolean compareDocumentWithGold(String goldfile, String resultFile) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setCoalescing(true); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + DocumentBuilder db = factory.newDocumentBuilder(); + + Document goldD = db.parse(Paths.get(goldfile).toFile()); + goldD.normalizeDocument(); + Document resultD = db.parse(Paths.get(resultFile).toFile()); + resultD.normalizeDocument(); + return goldD.isEqualNode(resultD); + } + + /** * Prints error message if an exception is thrown - * @param ex The exception is thrown by test. + * @param ex The exception is thrown by test. */ public static void failUnexpected(Throwable ex) { fail(ERROR_MSG_HEADER, ex); @@ -84,10 +119,10 @@ /** * Prints error message if an exception is thrown when clean up a file. - * @param ex The exception is thrown in cleaning up a file. - * @param name Cleaning up file name. + * @param ex The exception is thrown in cleaning up a file. + * @param name Cleaning up file name. */ public static void failCleanup(IOException ex, String name) { fail(String.format(ERROR_MSG_CLEANUP, name), ex); - } + } }