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 Project: xmlunit   Author: xmlunit   File: test_Transform.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: xmlunit   Author: xmlunit   File: SimpleXpathEngine.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #3
Source Project: xmlunit   Author: xmlunit   File: SimpleXpathEngine.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #4
Source Project: xmlunit   Author: xmlunit   File: XMLUnit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #5
Source Project: xmlunit   Author: xmlunit   File: XMLUnit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #6
Source Project: xmlunit   Author: xmlunit   File: XMLUnit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #7
Source Project: xmlunit   Author: xmlunit   File: test_Transform.java    License: Apache License 2.0 5 votes vote down vote up
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 #8
Source Project: xmlunit   Author: xmlunit   File: test_XMLUnit.java    License: Apache License 2.0 5 votes vote down vote up
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 #9
Source Project: xmlunit   Author: xmlunit   File: test_XMLUnit.java    License: Apache License 2.0 5 votes vote down vote up
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 #10
Source Project: libreveris   Author: jlpoolen   File: Main.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
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 Project: ogham   Author: groupe-sii   File: HtmlUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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 #12
Source Project: xmlunit   Author: xmlunit   File: SimpleXpathEngine.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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 #13
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #15
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #16
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #17
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #18
Source Project: xmlunit   Author: xmlunit   File: XMLAssert.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #19
Source Project: xmlunit   Author: xmlunit   File: SimpleXpathEngine.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #20
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #21
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #22
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #23
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #24
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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 #25
Source Project: xmlunit   Author: xmlunit   File: XMLTestCase.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}