< prev index next >

test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java

Print this page

        

*** 20,34 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package jaxp.library; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import static org.testng.Assert.fail; /** * This is an interface provide basic support for JAXP functional test. */ public class JAXPTestUtilities { --- 20,38 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ 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. */ public class JAXPTestUtilities {
*** 73,82 **** --- 77,117 ---- return Files.readAllLines(Paths.get(goldfile)). equals(Files.readAllLines(Paths.get(outputfile))); } /** + * 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. */ public static void failUnexpected(Throwable ex) { fail(ERROR_MSG_HEADER, ex);
< prev index next >