org.custommonkey.xmlunit.exceptions.ConfigurationException Java Examples
The following examples show how to use
org.custommonkey.xmlunit.exceptions.ConfigurationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: test_Transform.java From xmlunit with Apache License 2.0 | 6 votes |
public void testUnwrappingOfXMLUnitException() throws Exception { final Exception inner = new NullPointerException(); Transform.Trans<String> t = new Transform.Trans<String>() { @Override public String transform() { throw new XMLUnitException(inner); } }; try { Transform.withExceptionHandling(t); fail("should have thrown an exception"); } catch (XMLUnitRuntimeException ex) { assertFalse(ex instanceof ConfigurationException); assertSame(inner, ex.getCause()); } }
Example #2
Source File: test_XMLUnit.java From xmlunit with Apache License 2.0 | 5 votes |
public void testTranslatesParserConfigurationExceptionTest() throws Exception { when(dbFactory.newDocumentBuilder()).thenThrow(new ParserConfigurationException()); DocumentBuilderFactory orig = XMLUnit.getTestDocumentBuilderFactory(); try { XMLUnit.setTestDocumentBuilderFactory(dbFactory); XMLUnit.newTestParser(); fail("should have thrown an exception"); } catch (ConfigurationException f) { // expected return; } finally { XMLUnit.setTestDocumentBuilderFactory(orig); } }
Example #3
Source File: test_XMLUnit.java From xmlunit with Apache License 2.0 | 5 votes |
public void testTranslatesParserConfigurationExceptionControl() throws Exception { when(dbFactory.newDocumentBuilder()).thenThrow(new ParserConfigurationException()); DocumentBuilderFactory orig = XMLUnit.getControlDocumentBuilderFactory(); try { XMLUnit.setControlDocumentBuilderFactory(dbFactory); XMLUnit.newControlParser(); fail("should have thrown an exception"); } catch (ConfigurationException f) { // expected return; } finally { XMLUnit.setControlDocumentBuilderFactory(orig); } }
Example #4
Source File: test_Transform.java From xmlunit with Apache License 2.0 | 5 votes |
public void testUnwrappingOfConfigurationException() throws Exception { final Exception inner = new NullPointerException(); Transform.Trans<String> t = new Transform.Trans<String>() { @Override public String transform() { throw new org.xmlunit.ConfigurationException(inner); } }; try { Transform.withExceptionHandling(t); fail("should have thrown an exception"); } catch (ConfigurationException ex) { assertSame(inner, ex.getCause()); } }
Example #5
Source File: XMLUnit.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Sets the XSLT version to set on stylesheets used internally. * * <p>Defaults to "1.0".</p> * * @throws ConfigurationException if the argument cannot be parsed * as a positive number. */ public static void setXSLTVersion(String s) { try { Number n = NumberFormat.getInstance(Locale.US).parse(s); if (n.doubleValue() < 0) { throw new ConfigurationException(s + " doesn't reperesent a" + " positive number."); } } catch (ParseException e) { throw new ConfigurationException(e); } xsltVersion = s; }
Example #6
Source File: XMLUnit.java From xmlunit with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #7
Source File: XMLUnit.java From xmlunit with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #8
Source File: SimpleXpathEngine.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Evaluate the result of executing the specified xpath syntax * <code>select</code> expression on the specified document * @param select * @param document * @return evaluated result */ public String evaluate(String select, Document document) throws ConfigurationException, XpathException { try { StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); performTransform(getValueTransformation(select), document, result); return writer.toString(); } catch (TransformerException ex) { throw new XpathException("Failed to apply stylesheet", ex); } }
Example #9
Source File: SimpleXpathEngine.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Execute the specified xpath syntax <code>select</code> expression * on the specified document and return the list of nodes (could have * length zero) that match * @param select * @param document * @return list of matching nodes */ public NodeList getMatchingNodes(String select, Document document) throws ConfigurationException, XpathException { try { return getXPathResultNode(select, document).getChildNodes(); } catch (TransformerException ex) { throw new XpathException("Failed to apply stylesheet", ex); } }
Example #10
Source File: Main.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
public void compare () { // Comparing try { output.println("Comparing " + controlFile + " to " + testFile); final Document controlDoc; final Document testDoc; try (InputStream cis = new FileInputStream(controlFile)) { controlDoc = new PositionalXMLReader().readXML(cis); } try (InputStream tis = new FileInputStream(testFile)) { testDoc = new PositionalXMLReader().readXML(tis); } // Tuning XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreWhitespace(true); ///XMLUnit.setIgnoreComments(true); NO!!!!!!!! // The setIgnoreComments triggers the use of XSLT transform // which 1/ ruins userdata and 2/ fails on xml:space and xml:lang. // Moreover, comments are actually ignored by Diff ///XMLUnit.setCompareUnmatched(false); NO need // Customization Filter filter = (filterFile != null) ? new BasicFilter(new FileInputStream(filterFile)) : null; Diff diff = new Diff(controlDoc, testDoc, null); diff.overrideElementQualifier( new ElementNameAndAttributeQualifier("number")); diff.overrideDifferenceListener( new MusicDifferenceListener(filter, output)); output.println("Similar: " + diff.similar()); output.println("Identical: " + diff.identical()); DetailedDiff detDiff = new DetailedDiff(diff); List differences = detDiff.getAllDifferences(); output.println(); output.println("Physical differences: " + differences.size()); int diffId = 0; for (Object object : differences) { Difference difference = (Difference) object; if (!difference.isRecoverable() && ((filter == null) || !filter.canIgnore(difference))) { diffId++; output.dump(diffId, difference); } } output.println("Logical differences: " + diffId); logger.info("Logical differences: {}", diffId); } catch (ConfigurationException | SAXException | IOException e) { e.printStackTrace(); } }
Example #11
Source File: SimpleXpathEngine.java From xmlunit with Apache License 2.0 | 3 votes |
/** * Execute the copy-of transform and return the resulting Document. * Used for XMLTestCase comparison * @param select * @param document * @throws ConfigurationException * @throws TransformerException * @return the Document created by the copy-of transform. */ protected Document getXPathResultAsDocument(String select, Document document) throws ConfigurationException, TransformerException, XpathException { DOMResult result = new DOMResult(); performTransform(getCopyTransformation(select), document, result); return (Document) result.getNode(); }
Example #12
Source File: HtmlUtils.java From ogham with Apache License 2.0 | 3 votes |
/** * Compare two HTML documents. The HTML strings are parsed into * {@link Document}s. The HTML are compared by elements and attributes, not * using directly using string. * * <p> * A {@link DetailedDiff} is provided to know if the documents are * "identical" or "similar": * <ul> * <li>Two documents are considered to be "identical" if they contain the * same elements and attributes in the same order.</li> * <li>Two documents are considered to be "similar" if they contain the same * elements and attributes regardless of order.</li> * </ul> * * * @param expected * the expected HTML * @param actual * the HTML content to check * @return a report that let you know differences between the two HTML * strings */ public static DetailedDiff compare(String expected, String actual) { if (expected == null) { throw new IllegalArgumentException("expected html can't be null"); } try { HTMLDocumentBuilder builder = new HTMLDocumentBuilder(new TolerantSaxDocumentBuilder(XMLUnit.newTestParser())); Document expectedDoc = builder.parse(expected); Document actualDoc = builder.parse(actual==null ? "" : actual); return new DetailedDiff(XMLUnit.compareXML(expectedDoc, actualDoc)); } catch (SAXException | IOException | ConfigurationException | ParserConfigurationException e) { throw new ComparisonException("Failed to compare HTML", e); } }
Example #13
Source File: SimpleXpathEngine.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Testable method to execute the copy-of transform and return the root * node of the resulting Document. * @param select * @param document * @throws ConfigurationException * @throws TransformerException * @return the root node of the Document created by the copy-of transform. */ protected Node getXPathResultNode(String select, Document document) throws ConfigurationException, TransformerException, XpathException { return getXPathResultAsDocument(select, document).getDocumentElement(); }
Example #14
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a piece of XML contains valid XML: the input must * contain a DOCTYPE declaration to be validated * @param xml * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(InputSource xml) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xml); }
Example #15
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE declaration to be validated * @param xmlString * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(String xmlString) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xmlString); }
Example #16
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a piece of XML contains valid XML: the document must * contain a DOCTYPE to be validated, but the validation will use the * systemId to obtain the DTD * @param xml * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(InputSource xml, String systemId) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xml, systemId); }
Example #17
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE to be validated, but the validation will use the * systemId to obtain the DTD * @param xmlString * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(String xmlString, String systemId) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xmlString, systemId); }
Example #18
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a piece of XML contains valid XML: the document * will be given a DOCTYPE to be validated with the name and * systemId specified regardless of whether it already contains a * doctype declaration. * @param xml * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(InputSource xml, String systemId, String doctype) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xml, systemId, doctype); }
Example #19
Source File: XMLTestCase.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String will * be given a DOCTYPE to be validated with the name and systemId specified * regardless of whether it already contains a doctype declaration. * @param xmlString * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public void assertXMLValid(String xmlString, String systemId, String doctype) throws SAXException, ConfigurationException { XMLAssert.assertXMLValid(xmlString, systemId, doctype); }
Example #20
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String will * be given a DOCTYPE to be validated with the name and systemId specified * regardless of whether it already contains a doctype declaration. * @param xmlString * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(new StringReader(xmlString), systemId, doctype)); }
Example #21
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a piece of XML contains valid XML: the document * will be given a DOCTYPE to be validated with the name and * systemId specified regardless of whether it already contains a * doctype declaration. * @param xml * @param systemId * @param doctype * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId, String doctype) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId, doctype)); }
Example #22
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE to be validated, but the validation will use the * systemId to obtain the DTD * @param xmlString * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString, systemId)); }
Example #23
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE to be validated, but the * validation will use the systemId to obtain the DTD * @param xml * @param systemId * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml, String systemId) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml, systemId)); }
Example #24
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that a String containing XML contains valid XML: the String must * contain a DOCTYPE declaration to be validated * @param xmlString * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(String xmlString) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xmlString)); }
Example #25
Source File: XMLAssert.java From xmlunit with Apache License 2.0 | 2 votes |
/** * Assert that an InputSource containing XML contains valid XML: * the document must contain a DOCTYPE declaration to be validated * @param xml * @throws SAXException * @throws ConfigurationException if validation could not be turned on * @see Validator */ public static void assertXMLValid(InputSource xml) throws SAXException, ConfigurationException { assertXMLValid(new Validator(xml)); }