/** * Overide the DocumentBuilder to use to parse control documents. * This is useful when comparing the output of two different * parsers. Note: setting the control parser before any test cases * are run will affect the test parser as well. */ public static void setControlParser(String className) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className); controlBuilderFactory = null; controlBuilderFactory = getControlDocumentBuilderFactory(); } /**
/** * Overide the DocumentBuilder to use to parse control documents. * This is useful when comparing the output of two different * parsers. Note: setting the control parser before any test cases * are run will affect the test parser as well. */ public static void setControlParser(String className) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className); controlBuilderFactory = null; controlBuilderFactory = getControlDocumentBuilderFactory(); } /**
/** * 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 control * XML in an XMLTestCase. * @return parser for control values * @throws ConfigurationException */ public static DocumentBuilder newControlParser() throws ConfigurationException { try { controlBuilderFactory = getControlDocumentBuilderFactory(); DocumentBuilder builder = controlBuilderFactory.newDocumentBuilder(); if (controlEntityResolver!=null) { builder.setEntityResolver(controlEntityResolver); } return builder; } catch (ParserConfigurationException ex) { throw new ConfigurationException(ex); } }
/** * Get the <code>DocumentBuilder</code> instance used to parse the control * XML in an XMLTestCase. * @return parser for control values * @throws ConfigurationException */ public static DocumentBuilder newControlParser() throws ConfigurationException { try { controlBuilderFactory = getControlDocumentBuilderFactory(); DocumentBuilder builder = controlBuilderFactory.newDocumentBuilder(); if (controlEntityResolver!=null) { builder.setEntityResolver(controlEntityResolver); } 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)); }
prettyXml); Document expectedDocument = XMLUnit.getControlDocumentBuilderFactory() .newDocumentBuilder() .parse(new InputSource(new StringReader(TEST_XML)));
assertXpathEvaluatesTo("1", "count(/*[local-name()='metadata']/*[local-name()='quality' and string(.)='0'])", actual); XMLUnit.getControlDocumentBuilderFactory().setNamespaceAware(false); XMLAssert.assertXpathEvaluatesTo("rest-readerread", "//permissions/permission[role-name[. = 'rest-reader'] and capability[. = 'read']]", actual); XMLAssert.assertXpathEvaluatesTo("rest-writerupdate", "//permissions/permission[role-name[. = 'rest-writer'] and capability[. = 'update']]", actual); assertXpathEvaluatesTo("1", "count(/*[local-name()='metadata']/*[local-name()='quality' and string(.)='0'])", actual); XMLUnit.getControlDocumentBuilderFactory().setNamespaceAware(false); XMLAssert.assertXpathEvaluatesTo("rest-readerread", "//permissions/permission[role-name[. = 'rest-reader'] and capability[. = 'read']]", actual); XMLAssert.assertXpathEvaluatesTo("rest-writerupdate", "//permissions/permission[role-name[. = 'rest-writer'] and capability[. = 'update']]", actual);