/** * Overide the DocumentBuilder to use to parser test documents. * This is useful when comparing the output of two different * parsers. Note: setting the test parser before any test cases * are run will affect the control parser as well. */ public static void setTestParser(String className) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className); testBuilderFactory = null; testBuilderFactory = getTestDocumentBuilderFactory(); } /**
/** * Overide the DocumentBuilder to use to parser test documents. * This is useful when comparing the output of two different * parsers. Note: setting the test parser before any test cases * are run will affect the control parser as well. */ public static void setTestParser(String className) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className); testBuilderFactory = null; testBuilderFactory = getTestDocumentBuilderFactory(); } /**
/** * Whether the parser shall be instructed to expand entity references. * * <p>Defaults to false.</p> * * @see javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences */ public static void setExpandEntityReferences(boolean b) { expandEntities = b; getControlDocumentBuilderFactory().setExpandEntityReferences(b); getTestDocumentBuilderFactory().setExpandEntityReferences(b); }
/** * Whether the parser shall be instructed to expand entity references. * * <p>Defaults to false.</p> * * @see javax.xml.parsers.DocumentBuilderFactory#setExpandEntityReferences */ public static void setExpandEntityReferences(boolean b) { expandEntities = b; getControlDocumentBuilderFactory().setExpandEntityReferences(b); getTestDocumentBuilderFactory().setExpandEntityReferences(b); }
/** * Whether to ignore whitespace when comparing node values. * * <p>This method also invokes * <code>setIgnoringElementContentWhitespace()</code> on the * underlying control AND test document builder factories.</p> * * <p>Setting this parameter has no effect on {@link * setNormalizeWhitespace whitespace inside texts}.</p> */ public static void setIgnoreWhitespace(boolean ignore){ ignoreWhitespace = ignore; getControlDocumentBuilderFactory().setIgnoringElementContentWhitespace(ignore); getTestDocumentBuilderFactory().setIgnoringElementContentWhitespace(ignore); }
/** * Whether to ignore whitespace when comparing node values. * * <p>This method also invokes * <code>setIgnoringElementContentWhitespace()</code> on the * underlying control AND test document builder factories.</p> * * <p>Setting this parameter has no effect on {@link * #setNormalizeWhitespace whitespace inside texts}.</p> */ public static void setIgnoreWhitespace(boolean ignore){ ignoreWhitespace = ignore; getControlDocumentBuilderFactory().setIgnoringElementContentWhitespace(ignore); getTestDocumentBuilderFactory().setIgnoringElementContentWhitespace(ignore); }
/** * Get the <code>DocumentBuilder</code> instance used to parse the test XML * in an XMLTestCase. * @return parser for test values * @throws ConfigurationException */ public static DocumentBuilder newTestParser() throws ConfigurationException { try { testBuilderFactory = getTestDocumentBuilderFactory(); DocumentBuilder builder = testBuilderFactory.newDocumentBuilder(); if (testEntityResolver!=null) { builder.setEntityResolver(testEntityResolver); } return builder; } catch (ParserConfigurationException ex) { throw new ConfigurationException(ex); } }
/** * Get the <code>DocumentBuilder</code> instance used to parse the test XML * in an XMLTestCase. * @return parser for test values * @throws ConfigurationException */ public static DocumentBuilder newTestParser() throws ConfigurationException { try { testBuilderFactory = getTestDocumentBuilderFactory(); DocumentBuilder builder = testBuilderFactory.newDocumentBuilder(); if (testEntityResolver!=null) { builder.setEntityResolver(testEntityResolver); } return builder; } catch (ParserConfigurationException ex) { throw new ConfigurationException(ex); } }
/** * Whether CDATA sections and Text nodes should be considered the same. * * <p>The default is false.</p> * * <p>This also set the DocumentBuilderFactory's {@link * javax.xml.parsers.DocumentBuilderFactory#setCoalescing * coalescing} flag on the factories for the control and test * document.</p> */ public static void setIgnoreDiffBetweenTextAndCDATA(boolean b) { ignoreDiffBetweenTextAndCDATA = b; getControlDocumentBuilderFactory().setCoalescing(b); getTestDocumentBuilderFactory().setCoalescing(b); }
/** * Whether CDATA sections and Text nodes should be considered the same. * * <p>The default is false.</p> * * <p>This also set the DocumentBuilderFactory's {@link * javax.xml.parsers.DocumentBuilderFactory#setCoalescing * coalescing} flag on the factories for the control and test * document.</p> */ public static void setIgnoreDiffBetweenTextAndCDATA(boolean b) { ignoreDiffBetweenTextAndCDATA = b; getControlDocumentBuilderFactory().setCoalescing(b); getTestDocumentBuilderFactory().setCoalescing(b); }
/** * Tests that pretty printing works properly under normal circumstances. */ @Test public void testPrettyPrint() throws SAXException, IOException, ParserConfigurationException { when(adsApiConfiguration.getSensitiveXPaths()).thenReturn(new String[] {TEST_SENSITIVE_XPATH}); String prettyPrintedXml = createPrettyPrinter().prettyPrint(TEST_XML); String expectedXml = TEST_XML.replace("moe", "REDACTED"); Document expectedDocument = XMLUnit.getControlDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(expectedXml))); Document actualDocument = XMLUnit.getTestDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(prettyPrintedXml))); XMLAssert.assertXMLEqual( XMLUnit.getWhitespaceStrippedDocument(expectedDocument), XMLUnit.getWhitespaceStrippedDocument(actualDocument)); }
.parse(new InputSource(new StringReader(TEST_XML))); Document actualDocument = XMLUnit.getTestDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(prettyXml)));