From: <bo...@us...> - 2015-03-08 06:00:04
|
Revision: 593 http://sourceforge.net/p/xmlunit/code/593 Author: bodewig Date: 2015-03-08 05:59:53 +0000 (Sun, 08 Mar 2015) Log Message: ----------- backport tests and a fix from 2.0 Modified Paths: -------------- trunk/src/java/org/custommonkey/xmlunit/Diff.java trunk/src/java/org/custommonkey/xmlunit/DoctypeInputStream.java trunk/src/java/org/custommonkey/xmlunit/DoctypeReader.java trunk/src/java/org/custommonkey/xmlunit/XMLAssert.java trunk/src/java/org/custommonkey/xmlunit/XMLTestCase.java trunk/src/java/org/custommonkey/xmlunit/XMLUnit.java trunk/src/user-guide/XMLUnit-Java.xml trunk/tests/java/org/custommonkey/xmlunit/AbstractDoctypeTests.java trunk/tests/java/org/custommonkey/xmlunit/test_AbstractNodeTester.java trunk/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/tests/java/org/custommonkey/xmlunit/test_Diff.java trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java trunk/tests/java/org/custommonkey/xmlunit/test_TolerantSaxDocumentBuilder.java trunk/tests/java/org/custommonkey/xmlunit/test_Transform.java trunk/tests/java/org/custommonkey/xmlunit/test_XMLTestCase.java trunk/tests/java/org/custommonkey/xmlunit/test_XMLUnit.java Added Paths: ----------- trunk/tests/java/org/custommonkey/xmlunit/test_DoctypeSupport.java trunk/tests/java/org/custommonkey/xmlunit/test_XMLAssert.java Modified: trunk/src/java/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/Diff.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/Diff.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2014 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2014-2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -132,8 +132,7 @@ * Construct a Diff that compares the XML in two JAXP DOMSources */ public Diff(DOMSource control, DOMSource test) { - this(control.getNode().getOwnerDocument(), - test.getNode().getOwnerDocument()); + this(toDocument(control), toDocument(test)); } /** @@ -425,4 +424,8 @@ : differenceEngine; } + private static Document toDocument(DOMSource d) { + Node n = d.getNode(); + return n instanceof Document ? (Document) n : n.getOwnerDocument(); + } } Modified: trunk/src/java/org/custommonkey/xmlunit/DoctypeInputStream.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/DoctypeInputStream.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/DoctypeInputStream.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -46,7 +46,7 @@ * conforms to a different DTD. * Combines InputStream semantics with the ability to specify a target doctype * for a byte stream containing XML markup. - * Used by Validator class to wrap an InputStrea, when performing validation of a + * Used by Validator class to wrap an InputStream, when performing validation of a * document against a DTD. * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> */ Modified: trunk/src/java/org/custommonkey/xmlunit/DoctypeReader.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2015-03-08 05:59:53 UTC (rev 593) @@ -51,7 +51,7 @@ */ public class DoctypeReader extends Reader { - private final Reader originalReader; + private final BufferedReader originalReader; private final StringBuffer sourceBuffer = new StringBuffer(1024); private final DoctypeSupport support; @@ -67,12 +67,12 @@ public DoctypeReader(Reader originalSource, String doctypeName, String systemID) { originalReader = originalSource instanceof BufferedReader - ? originalSource : new BufferedReader(originalSource); + ? (BufferedReader) originalSource : new BufferedReader(originalSource); support = new DoctypeSupport(doctypeName, systemID, new DoctypeSupport.Readable() { public int read() throws IOException { - return originalReader.read(); + return DoctypeReader.this.originalReader.read(); } }, true, null); @@ -92,19 +92,13 @@ * @return the contents of the originalSource within a StringBuffer * @throws IOException if thrown while reading from the original source */ - private StringBuffer getContent(Reader originalSource) + private StringBuffer getContent(BufferedReader originalSource) throws IOException { if (sourceBuffer.length() == 0) { - BufferedReader bufferedReader; - if (originalSource instanceof BufferedReader) { - bufferedReader = (BufferedReader) originalSource; - } else { - bufferedReader = new BufferedReader(originalSource); - } String newline = System.getProperty("line.separator"); String source; boolean atFirstLine = true; - while ((source = bufferedReader.readLine()) != null) { + while ((source = originalSource.readLine()) != null) { if (atFirstLine) { atFirstLine = false; } else { @@ -113,7 +107,7 @@ sourceBuffer.append(source); } - bufferedReader.close(); + originalSource.close(); } return sourceBuffer; Modified: trunk/src/java/org/custommonkey/xmlunit/XMLAssert.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/XMLAssert.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/XMLAssert.java 2015-03-08 05:59:53 UTC (rev 593) @@ -809,9 +809,8 @@ fail("Expected test value NOT to be equal to control but both were " + test); } - } else if (test != null) { - fail("control xPath evaluated to empty node set, " - + "but test xPath evaluated to " + test); + } else if (test == null) { + fail("Expected test value NOT to be equal to control but both were empty"); } } Modified: trunk/src/java/org/custommonkey/xmlunit/XMLTestCase.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2015-03-08 05:59:53 UTC (rev 593) @@ -41,7 +41,6 @@ import java.io.IOException; import java.io.Reader; -import java.io.StringReader; import junit.framework.TestCase; import org.w3c.dom.Document; @@ -113,7 +112,7 @@ */ public Diff compareXML(String control, Reader test) throws SAXException, IOException { - return XMLUnit.compareXML(new StringReader(control), test); + return XMLUnit.compareXML(control, test); } /** @@ -126,7 +125,7 @@ */ public Diff compareXML(Reader control, String test) throws SAXException, IOException { - return XMLUnit.compareXML(control, new StringReader(test)); + return XMLUnit.compareXML(control, test); } /** Modified: trunk/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/src/java/org/custommonkey/xmlunit/XMLUnit.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/java/org/custommonkey/xmlunit/XMLUnit.java 2015-03-08 05:59:53 UTC (rev 593) @@ -178,6 +178,13 @@ return controlEntityResolver; } + /** + * Obtains the EntityResolver to be added to all new test parsers. + */ + public static EntityResolver getTestEntityResolver() { + return testEntityResolver; + } + /** * Get the <code>DocumentBuilderFactory</code> instance used to instantiate * parsers for the control XML in an XMLTestCase. @@ -559,7 +566,8 @@ * @return current version */ public static String getVersion() { - return "1.3alpha"; + // FIXME should read a property + return "1.7alpha"; } /** Modified: trunk/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/src/user-guide/XMLUnit-Java.xml 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/src/user-guide/XMLUnit-Java.xml 2015-03-08 05:59:53 UTC (rev 593) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE article PUBLIC "-//OASIS//DTD Simplified DocBook XML V1.1b1//EN" "http://docbook.org/xml/simple/1.1b1/sdocbook.dtd"> <!-- -Copyright (c) 2001-2014, Jeff Martin, Tim Bacon +Copyright (c) 2001-2015, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -3861,6 +3861,40 @@ </section> </section> + <section id="Changes 1.7"> + <title>Changes from XMLUnit 1.6 to 1.7</title> + + <section id="Breaking Changes 1.7"> + <title>Breaking Changes</title> + + <itemizedlist> + <listitem> + </listitem> + </itemizedlist> + </section> + + <section id="New Features 1.7"> + <title>New Features</title> + + <itemizedlist> + <listitem> + </listitem> + </itemizedlist> + </section> + + <section id="Bugfixes 1.7"> + <title>Important Bug Fixes</title> + + <itemizedlist> + <listitem> + The <literal>Diff</literal> constructor using + <literal>DOMSource</literal> didn't work when the source's + <literal>Node</literals> was a <literal>Document</literals>. + </listitem> + </itemizedlist> + </section> + </section> + </appendix> </article> Modified: trunk/tests/java/org/custommonkey/xmlunit/AbstractDoctypeTests.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/AbstractDoctypeTests.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/AbstractDoctypeTests.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 200, Jeff Martin, Tim Bacon +Copyright (c) 2001-2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -48,6 +48,7 @@ private static final String COMMENT = "<!-- comment -->"; protected static final String NO_DTD = "<document><element>one</element></document>"; + private static final String PI = "<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>"; public abstract void testGetContent() throws IOException; @@ -95,6 +96,30 @@ "ni", "shrubbery"); } + public void testInternalDTDWithTwoComments() throws IOException { + assertEquals(test_Constants.XML_DECLARATION + + "<!DOCTYPE ni SYSTEM \"shrubbery\">" + + COMMENT + + COMMENT, + test_Constants.XML_DECLARATION + + COMMENT + + COMMENT + + test_Constants.CHUCK_JONES_RIP_DTD_DECL, + "ni", "shrubbery"); + } + + public void testInternalDTDWithPIAfterComments() throws IOException { + assertEquals(test_Constants.XML_DECLARATION + + "<!DOCTYPE ni SYSTEM \"shrubbery\">" + + COMMENT + + PI, + test_Constants.XML_DECLARATION + + COMMENT + + PI + + test_Constants.CHUCK_JONES_RIP_DTD_DECL, + "ni", "shrubbery"); + } + public void testExternalDTDWithComment() throws IOException { assertEquals("<!DOCTYPE ni SYSTEM \"shrubbery\">" + COMMENT, @@ -114,6 +139,18 @@ "ni", "shrubbery"); } + public void testLeadingWhitespace() throws IOException { + assertEquals(" <!DOCTYPE ni SYSTEM \"shrubbery\">" + NO_DTD, + " " + NO_DTD, "ni", "shrubbery"); + } + + public void testWhitespaceAfterComment() throws IOException { + assertEquals("<!DOCTYPE ni SYSTEM \"shrubbery\">" + + COMMENT + " " + + NO_DTD, + COMMENT + " " + NO_DTD, "ni", "shrubbery"); + } + public AbstractDoctypeTests(String name) { super(name); } Modified: trunk/tests/java/org/custommonkey/xmlunit/test_AbstractNodeTester.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_AbstractNodeTester.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_AbstractNodeTester.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2007, Jeff Martin, Tim Bacon +Copyright (c) 2007,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -39,8 +39,10 @@ import junit.framework.Assert; import junit.framework.TestCase; +import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; +import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; @@ -55,6 +57,12 @@ */ public class test_AbstractNodeTester extends TestCase { + private Document doc; + + public void setUp() { + doc = XMLUnit.newControlParser().newDocument(); + } + public void testExactlyOncePerMethod() throws Exception { String testXml = "<!DOCTYPE foo [" + "<!ELEMENT foo (#PCDATA)>" @@ -88,6 +96,99 @@ tester.verify(); } + // seems to never get called in real tests + public void testAttribute() { + AbstractNodeTester t = new AbstractNodeTester() { }; + Attr n = doc.createAttribute("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testCDATASection() { + AbstractNodeTester t = new AbstractNodeTester() { }; + CDATASection n = doc.createCDATASection("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testComment() { + AbstractNodeTester t = new AbstractNodeTester() { }; + Comment n = doc.createComment("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testElement() { + AbstractNodeTester t = new AbstractNodeTester() { }; + Element n = doc.createElement("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testEntityReference() { + AbstractNodeTester t = new AbstractNodeTester() { }; + EntityReference n = doc.createEntityReference("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testProcessingInstruction() { + AbstractNodeTester t = new AbstractNodeTester() { }; + ProcessingInstruction n = doc.createProcessingInstruction("foo", "bar"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + public void testTextNode() { + AbstractNodeTester t = new AbstractNodeTester() { }; + Text n = doc.createTextNode("foo"); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + + // never called as NodeTest directly jumps to the document element + public void testDocumentType() throws Exception { + AbstractNodeTester t = new AbstractNodeTester() { }; + DocumentType n = XMLUnit + .buildControlDocument("<!DOCTYPE Book PUBLIC \"XMLUNIT/TESTS/PUB1\" \"../test-resources/Book.dtd\">" + + "<Book/>") + .getDoctype(); + try { + t.testNode(n, null); + fail("expected exception"); + } catch (NodeTestException ex) { + assertSame(n, ex.getNode()); + } + } + private class ExactlyOncePerMethod extends AbstractNodeTester { private boolean cdataCalled; Modified: trunk/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2010,2013 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010,2013,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ import java.io.Reader; import java.util.Iterator; import java.util.List; +import javax.xml.transform.dom.DOMSource; import org.custommonkey.xmlunit.examples.MultiLevelElementNameAndTextQualifier; import org.w3c.dom.Document; @@ -330,6 +331,10 @@ return new DetailedDiff(super.buildDiff(control, test, engine)); } + protected Diff buildDiff(DOMSource control, DOMSource test) { + return new DetailedDiff(super.buildDiff(control, test)); + } + public test_DetailedDiff(String name) { super(name); firstForecast = "<weather><today icon=\"clouds\" temp=\"17\">" Modified: trunk/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_Diff.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_Diff.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2013, Jeff Martin, Tim Bacon +Copyright (c) 2001-2013,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ import java.io.Reader; import java.util.HashSet; import java.util.Set; +import javax.xml.transform.dom.DOMSource; import junit.framework.TestCase; @@ -475,6 +476,29 @@ assertFalse(diff.toString(), diff.identical()); } + public void testUsingDOMSourceFromDocument() throws Exception { + Document control = + XMLUnit.buildTestDocument("<!DOCTYPE skinconfig []>" + + "<!--abcd--><root></root>"); + Document test = + XMLUnit.buildControlDocument("<!DOCTYPE skinconfig [<!--abcd-->]>" + + "<root></root>"); + Diff diff = buildDiff(new DOMSource(control), new DOMSource(test)); + assertTrue(diff.toString(), diff.identical()); + } + + public void testUsingDOMSourceFromElement() throws Exception { + Document control = + XMLUnit.buildTestDocument("<!DOCTYPE skinconfig []>" + + "<!--abcd--><root></root>"); + Document test = + XMLUnit.buildControlDocument("<!DOCTYPE skinconfig [<!--abcd-->]>" + + "<root></root>"); + Diff diff = buildDiff(new DOMSource(control.getDocumentElement()), + new DOMSource(test.getDocumentElement())); + assertTrue(diff.toString(), diff.identical()); + } + protected Diff buildDiff(Document control, Document test) { return new Diff(control, test); } @@ -493,6 +517,10 @@ XMLUnit.buildTestDocument(test), engine); } + protected Diff buildDiff(DOMSource control, DOMSource test) { + return new Diff(control, test); + } + /** * Construct a test * @param name Test name @@ -906,7 +934,7 @@ "<child amount=\"100\" />" + "</tag>"; - Diff diff = new Diff(control, test); + Diff diff = buildDiff(control, test); diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertTrue(diff.toString(), diff.similar()); @@ -947,7 +975,7 @@ String control = "<ns2:Square xsi:type=\"ns2:Shape\" " + "xmlns:ns2=\"http://example.com/\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; - Diff diff = new Diff(control, test); + Diff diff = buildDiff(control, test); assertTrue(diff.toString(), diff.similar()); } @@ -961,7 +989,7 @@ + "<ns2:Square xsi:type=\"ns2:Shape\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>" + "</ns2:Shapes>"; - Diff diff = new Diff(control, test); + Diff diff = buildDiff(control, test); assertTrue(diff.toString(), diff.similar()); } @@ -975,7 +1003,7 @@ + "xmlns:ns1=\"http://example.com/\" " + "xmlns:ns2=\"http://example.com/another-uri/\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; - Diff diff = new Diff(control, test); + Diff diff = buildDiff(control, test); assertFalse(diff.toString(), diff.similar()); } public void testXsiNil() throws Exception { @@ -984,7 +1012,7 @@ String control = "<foo xsi:nil=\"false\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; - Diff diff = new Diff(control, test); + Diff diff = buildDiff(control, test); assertFalse(diff.toString(), diff.similar()); } } Modified: trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008,2013-2014 Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2013-2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -631,6 +631,22 @@ assertNull("13th test xpath", listener.testXpath); } + public void testXpathLocation13Reversed() throws Exception { + engine = new DifferenceEngine(PSEUDO_DETAILED_DIFF); + String control = "<stuff><?item data?></stuff>"; + String test = "<stuff><item id=\"1\"/><item id=\"2\"/></stuff>"; + listenToDifferences(control, test); + // mutiple Differences, we only see the last one, missing second element + assertEquals("null", listener.expected); + assertEquals("item", listener.actual); + assertEquals("13 difference type", + DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, + listener.comparingWhat); + assertNull("13th-r control xpath", listener.controlXpath); + assertEquals("13th-r test xpath", "/stuff[1]/item[2]", + listener.testXpath); + } + public void testMissingChildNS() throws Exception { engine = new DifferenceEngine(PSEUDO_DETAILED_DIFF); String control = "<stuff xmlns=\"http://example.org/\">" @@ -1002,6 +1018,40 @@ listener.comparingWhat); } + public void testDoctypeDifferences() throws Exception { + String control = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!DOCTYPE Book PUBLIC \"XMLUNIT/TESTS/PUB1\" \"../test-resources/Book.dtd\">" + + "<Book/>"; + String test = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!DOCTYPE Book PUBLIC \"XMLUNIT/TESTS/PUB2\" \"../test-resources/Book.dtd\">" + + "<Book/>"; + listenToDifferences(control, test); + assertTrue(listener.different); + } + + public void testTextAndCDATA() throws Exception { + String control = "<stuff><![CDATA[foo]]></stuff>"; + String test = "<stuff>foo</stuff>"; + listenToDifferences(control, test); + assertTrue(listener.different); + assertEquals("textAndCdata control xpath", "/stuff[1]/text()[1]", + listener.controlXpath); + assertEquals("textAndCdata test xpath", "/stuff[1]/text()[1]", + listener.testXpath); + } + + public void testIgnoreDiffBetweenTextAndCDATA() throws Exception { + String control = "<stuff><![CDATA[foo]]></stuff>"; + String test = "<stuff>foo</stuff>"; + try { + XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); + listenToDifferences(control, test); + assertFalse(listener.different); + } finally { + XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false); + } + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { Document controlDoc = XMLUnit.buildControlDocument(control); Added: trunk/tests/java/org/custommonkey/xmlunit/test_DoctypeSupport.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_DoctypeSupport.java (rev 0) +++ trunk/tests/java/org/custommonkey/xmlunit/test_DoctypeSupport.java 2015-03-08 05:59:53 UTC (rev 593) @@ -0,0 +1,57 @@ +/* +****************************************************************** +Copyright (c) 2015 Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the XMLUnit nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit; + +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; + +public class test_DoctypeSupport extends TestCase { + + public void testUnsupportedEncoding() { + try { + new DoctypeSupport("foo", "foo", new DoctypeSupport.Readable() { + public int read() { + return 1; + } + }, false, "foo"); + fail("should throw an exception"); + } catch (XMLUnitRuntimeException ex) { + // expected + } + } +} Property changes on: trunk/tests/java/org/custommonkey/xmlunit/test_DoctypeSupport.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/tests/java/org/custommonkey/xmlunit/test_TolerantSaxDocumentBuilder.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_TolerantSaxDocumentBuilder.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_TolerantSaxDocumentBuilder.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 200, Jeff Martin, Tim Bacon +Copyright (c) 2001-2015, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -131,6 +131,11 @@ assertTrue(builder.getTrace(), builder.getTrace().indexOf("WARNING") != -1); } + // silly, but a no-op + public void testCharactersWithNegativeLength() { + builder.characters(null, 0, -1); + } + public void setUp() throws Exception { builder = new TolerantSaxDocumentBuilder(XMLUnit.newTestParser()); parser = SAXParserFactory.newInstance().newSAXParser(); Modified: trunk/tests/java/org/custommonkey/xmlunit/test_Transform.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_Transform.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_Transform.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -38,8 +38,10 @@ import java.io.File; import java.io.FileReader; +import java.io.StringReader; import org.custommonkey.xmlunit.exceptions.ConfigurationException; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; @@ -48,6 +50,7 @@ import junit.framework.TestSuite; import org.w3c.dom.Document; +import org.xml.sax.InputSource; /** * Test a Transform @@ -66,6 +69,17 @@ assertEquals(DOG, stripLineFeeds(transform.getResultString())); } + public void testGetResultStringViaInputSource() throws Exception { + transform = new Transform(new InputSource(new StringReader(FLEABALL)), animal); + assertEquals(DOG, stripLineFeeds(transform.getResultString())); + } + + public void testGetResultStringViaTwoInputSources() throws Exception { + transform = new Transform(new InputSource(new StringReader(FLEABALL)), + new InputSource(new FileReader(animal))); + assertEquals(DOG, stripLineFeeds(transform.getResultString())); + } + public void testGetResultDocument() throws Exception { transform = new Transform(FLEABALL, animal); Diff diff = new Diff(DOG, transform); @@ -144,6 +158,14 @@ } } + public void testParameterHandling() { + transform = new Transform(FLEABALL, animal); + transform.setParameter("foo", "bar"); + assertEquals("bar", transform.getParameter("foo")); + transform.clearParameters(); + assertNull(transform.getParameter("foo")); + } + private void assertNotEquals(Object expected, Object actual) { if (expected.equals(actual)) { fail("Expected " + expected + " different to actual!"); Added: trunk/tests/java/org/custommonkey/xmlunit/test_XMLAssert.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_XMLAssert.java (rev 0) +++ trunk/tests/java/org/custommonkey/xmlunit/test_XMLAssert.java 2015-03-08 05:59:53 UTC (rev 593) @@ -0,0 +1,174 @@ +/* +****************************************************************** +Copyright (c) 2015 Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the XMLUnit nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; +import org.xml.sax.InputSource; +import org.w3c.dom.Node; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.examples.CountingNodeTester; + +public class test_XMLAssert extends TestCase { + public void testAssertXMLEqualStringDiffBooleanWithMatch() throws Exception { + Diff d = XMLUnit.compareXML("<foo/>", "<foo/>"); + XMLAssert.assertXMLEqual("msg", d, true); + try { + XMLAssert.assertXMLEqual("msg", d, false); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertXMLEqualStringDiffBooleanWithDiff() throws Exception { + Diff d = XMLUnit.compareXML("<foo/>", "<bar/>"); + XMLAssert.assertXMLEqual("msg", d, false); + try { + XMLAssert.assertXMLEqual("msg", d, true); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertXMIdenticalDiffBooleanWithMatch() throws Exception { + Diff d = XMLUnit.compareXML("<foo/>", "<foo/>"); + XMLAssert.assertXMLIdentical(d, true); + try { + XMLAssert.assertXMLIdentical(d, false); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertXMIdenticalDiffBooleanWithDiff() throws Exception { + Diff d = XMLUnit.compareXML("<foo/>", "<bar/>"); + XMLAssert.assertXMLIdentical(d, false); + try { + XMLAssert.assertXMLIdentical(d, true); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertXpathsNotEqual() throws Exception { + String xpathXML = "<foo><bar/></foo>"; + XMLAssert.assertXpathsNotEqual("/foo", + new InputSource(new StringReader(xpathXML)), + "/foo/bar", + new InputSource(new StringReader(xpathXML))); + } + + public void testAssertXpathValuesNotEqual() throws Exception { + String controlXML = "<foo>bar</foo>"; + try { + XMLAssert.assertXpathValuesNotEqual("/foo", controlXML, + "/foo", controlXML); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertXpathValuesNotEqualNoMatch() throws Exception { + String controlXML = "<foo>bar</foo>"; + try { + XMLAssert.assertXpathValuesNotEqual("/baz", controlXML, + "/baz", controlXML); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testXpathEvaluatesToQualifiedName() throws Exception { + String faultDocument = "<env:Envelope " + + "xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + + "<env:Body><env:Fault><faultcode>env:Server</faultcode>" + + "<faultstring>marche pas</faultstring><detail/></env:Fault>" + + "</env:Body></env:Envelope>"; + Map namespaces = new HashMap(); + namespaces.put("env11", "http://schemas.xmlsoap.org/soap/envelope/"); + XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); + XMLAssert.assertXpathEvaluatesTo(QualifiedName.valueOf("env11:Server"), + "//env11:Envelope/env11:Body/" + + "env11:Fault/faultcode", + new InputSource(new StringReader(faultDocument))); + } + + public void testAssertNodeTestPassesWithMatch() throws Exception { + NodeTest test = new NodeTest(new StringReader(test_XMLTestCase.xpathValuesTestXML)); + NodeTester tester = new CountingNodeTester(1); + XMLAssert.assertNodeTestPasses(test, tester, new short[] { Node.TEXT_NODE }, true); + try { + XMLAssert.assertNodeTestPasses(test, tester, new short[] { Node.TEXT_NODE }, + false); + } catch (AssertionFailedError e) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testAssertNodeTestPassesWithDiff() throws Exception { + NodeTest test = new NodeTest(new StringReader(test_XMLTestCase.xpathValuesTestXML)); + NodeTester tester = new CountingNodeTester(1); + XMLAssert.assertNodeTestPasses(test, tester, new short[] { Node.ELEMENT_NODE }, + false); + try { + XMLAssert.assertNodeTestPasses(test, tester, new short[] { Node.ELEMENT_NODE }, + true); + } catch (AssertionFailedError e) { + // expected + return; + } + fail("should have thrown an exception"); + } +} Property changes on: trunk/tests/java/org/custommonkey/xmlunit/test_XMLAssert.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/tests/java/org/custommonkey/xmlunit/test_XMLTestCase.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_XMLTestCase.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_XMLTestCase.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2011,2014 Jeff Martin, Tim Bacon +Copyright (c) 2001-2011,2014-2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.xml.sax.InputSource; /** * Test case used to test the XMLTestCase @@ -99,6 +100,78 @@ } /** + * Test for the compareXML method for readers. + */ + public void testCompareXMLReaders() throws Exception { + for(int i=0;i<control.length;i++){ + assertEquals("compareXML case " + i + " failed", true, + compareXML(new StringReader(control[i]), + new StringReader(control[i])).similar()); + assertEquals("!compareXML case " + i + " failed", false, + compareXML(new StringReader(control[i]), + new StringReader(test[i])).similar()); + } + } + + /** + * Test for the compareXML method for InputSources. + */ + public void testCompareXMLInputSources() throws Exception { + for(int i=0;i<control.length;i++){ + assertEquals("compareXML case " + i + " failed", true, + compareXML(new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(control[i]))) + .similar()); + assertEquals("!compareXML case " + i + " failed", false, + compareXML(new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(test[i]))) + .similar()); + } + } + + /** + * Test for the compareXML method for Reader/String combination. + */ + public void testCompareXMLStringReader() throws Exception { + for(int i=0;i<control.length;i++){ + assertEquals("compareXML case " + i + " failed", true, + compareXML(new StringReader(control[i]), + control[i]).similar()); + assertEquals("!compareXML case " + i + " failed", false, + compareXML(new StringReader(control[i]), + test[i]).similar()); + } + } + + /** + * Test for the compareXML method for String/Reader combination. + */ + public void testCompareXMLReaderString() throws Exception { + for(int i=0;i<control.length;i++){ + assertEquals("compareXML case " + i + " failed", true, + compareXML(control[i], + new StringReader(control[i])).similar()); + assertEquals("!compareXML case " + i + " failed", false, + compareXML(control[i], + new StringReader(test[i])).similar()); + } + } + + /** + * Test for the compareXML method for Documents. + */ + public void testCompareXMLDocumentss() throws Exception { + for(int i=0;i<control.length;i++){ + Document controlDocument = XMLUnit.buildControlDocument(control[i]); + assertEquals("compareXML case " + i + " failed", true, + compareXML(controlDocument, controlDocument).similar()); + Document testDocument = XMLUnit.buildTestDocument(test[i]); + assertEquals("!compareXML case " + i + " failed", false, + compareXML(controlDocument, testDocument).similar()); + } + } + + /** * Test the comparision of two files */ public void testXMLEqualsFiles() throws Exception { @@ -129,36 +202,149 @@ } /** - * Test for the assertXMLEquals method. + * Test for the assertXMLEqual method. */ public void testXMLEqualsStrings() throws Exception { for(int i=0;i<control.length;i++){ - assertXMLEqual("assertXMLEquals test case " + i + " failed", + assertXMLEqual("assertXMLEqual test case " + i + " failed", control[i], control[i]); - assertXMLNotEqual("assertXMLNotEquals test case" + i + " failed", + assertXMLNotEqual("assertXMLNotEqual test case" + i + " failed", control[i], test[i]); } } /** - * Test for the assertXMLEquals method. + * Test for the assertXMLEqual method for String and InputSources. */ - public void testXMLEqualsDocuments() throws Exception { + public void testXMLEqualsStringInputSources() throws Exception { + for(int i=0;i<control.length;i++){ + assertXMLEqual("assertXMLEqual test case " + i + " failed", + new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(control[i]))); + assertXMLNotEqual("assertXMLNotEqual test case" + i + " failed", + new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(test[i]))); + } + } + + /** + * Test for the assertXMLEqual method for InputSources. + */ + public void testXMLEqualsInputSources() throws Exception { + for(int i=0;i<control.length;i++){ + assertXMLEqual(new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(control[i]))); + assertXMLNotEqual(new InputSource(new StringReader(control[i])), + new InputSource(new StringReader(test[i]))); + } + } + + /** + * Test for the assertXMLEqual method. + */ + public void testXMLEqualsStringDocuments() throws Exception { Document controlDocument, testDocument; for(int i=0;i<control.length;i++){ controlDocument = XMLUnit.buildControlDocument(control[i]); - assertXMLEqual("assertXMLEquals test case " + i + " failed", + assertXMLEqual("assertXMLEqual test case " + i + " failed", controlDocument, controlDocument); testDocument = XMLUnit.buildTestDocument(test[i]); - assertXMLNotEqual("assertXMLNotEquals test case" + i + " failed", + assertXMLNotEqual("assertXMLNotEqual test case" + i + " failed", controlDocument, testDocument); } } + /** + * Test for the assertXMLEqual method. + */ + public void testXMLEqualsDocuments() throws Exception { + Document controlDocument, testDocument; + for(int i=0;i<control.length;i++){ + controlDocument = XMLUnit.buildControlDocument(control[i]); + assertXMLEqual(controlDocument, controlDocument); + testDocument = XMLUnit.buildTestDocument(test[i]); + assertXMLNotEqual(controlDocument, testDocument); + } + } + + /** + * Test for the assertXMLEqual method with Diff and boolean. + */ + public void testXMLEqualDiffBoolean() throws Exception { + for(int i=0;i<control.length;i++){ + Diff d = compareXML(control[i], control[i]); + assertXMLEqual(d, true); + d = compareXML(control[i], test[i]); + assertXMLEqual(d, false); + } + } + + /** + * Test for the assertXMLEqual method with String, Diff and boolean. + */ + public void testXMLEqualStringDiffBoolean() throws Exception { + for(int i=0;i<control.length;i++){ + Diff d = compareXML(control[i], control[i]); + assertXMLEqual("assertXMLEqual test case " + i + " failed", + d, true); + d = compareXML(control[i], test[i]); + assertXMLEqual("assertXMLEqual test case " + i + " failed", + d, false); + } + } + + public void testXMLEqualThrows() throws Exception { + Diff d = compareXML(control[0], test[0]); + try { + assertXMLEqual("should throw exception", d, true); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + public void testXMLIdenticalThrows() throws Exception { + Diff d = compareXML(control[0], test[0]); + try { + assertXMLIdentical("should throw exception", d, true); + } catch (AssertionFailedError f) { + // expected + return; + } + fail("should have thrown an exception"); + } + + /** + * Test for the assertXMLIdentical method with Diff and boolean. + */ + public void testXMLIdenticalDiffBoolean() throws Exception { + for(int i=0;i<control.length;i++){ + Diff d = compareXML(control[i], control[i]); + assertXMLIdentical(d, true); + d = compareXML(control[i], test[i]); + assertXMLIdentical(d, false); + } + } + + /** + * Test for the assertXMLIdentical method with String, Diff and boolean. + */ + public void testXMLIdenticalStringDiffBoolean() throws Exception { + for(int i=0;i<control.length;i++){ + Diff d = compareXML(control[i], control[i]); + assertXMLIdentical("assertXMLIdentical test case " + i + " failed", + d, true); + d = compareXML(control[i], test[i]); + assertXMLIdentical("assertXMLIdentical test case " + i + " failed", + d, false); + } + } + private static final String xpathValuesControlXML = "<root><outer attr=\"urk\"><inner attr=\"urk\">" + "controlDocument</inner></outer></root>"; - private static final String xpathValuesTestXML = + static final String xpathValuesTestXML = "<root><outer attr=\"urk\"><inner attr=\"ugh\">" + "testDocument</inner></outer></root>"; private static final String xpathValuesControlXMLNS = @@ -231,6 +417,22 @@ "//text()", xpathValuesTestXMLNS); } + public void testXpathValuesEqualUsingInputSource() throws Exception { + assertXpathValuesEqual("//text()", "//inner/text()", + new InputSource(new StringReader(xpathValuesControlXML))); + assertXpathValuesEqual("//inner/@attr", + new InputSource(new StringReader(xpathValuesControlXML)), + "//outer/@attr", + new InputSource(new StringReader(xpathValuesTestXML))); + + assertXpathValuesNotEqual("//inner/text()", "//outer/@attr", + new InputSource(new StringReader(xpathValuesControlXML))); + assertXpathValuesNotEqual("//inner/text()", + new InputSource(new StringReader(xpathValuesControlXML)), + "//text()", + new InputSource(new StringReader(xpathValuesTestXML))); + } + public void testXpathEvaluatesTo() throws Exception { assertXpathEvaluatesTo("urk", "//outer/@attr", xpathValuesControlXML); try { @@ -248,6 +450,15 @@ } catch (AssertionFailedError e) { } + assertXpathEvaluatesTo("ugh", "//inner/@attr", + new InputSource(new StringReader(xpathValuesTestXML))); + try { + assertXpathEvaluatesTo("yeah", "//outer/@attr", + new InputSource(new StringReader(xpathValuesTestXML))); + fail("Expected assertion to fail #3"); + } catch (AssertionFailedError e) { + } + } public void testXpathEvaluatesToNS() throws Exception { @@ -308,8 +519,16 @@ } } - public void testXMLValid() { - // see test_Validator class + public void testNodeTestInputSource() throws Exception { + NodeTester tester = new CountingNodeTester(1); + assertNodeTestPasses(new InputSource(new StringReader(xpathValuesControlXML)), + tester, Node.TEXT_NODE); + try { + assertNodeTestPasses(new InputSource(new StringReader(xpathValuesControlXML)), + tester, Node.ELEMENT_NODE); + fail("Expected node test failure #1!"); + } catch (AssertionFailedError e) { + } } private static final String TREES_OPEN = "<trees>"; @@ -358,6 +577,10 @@ testXpath[i], testDoc); assertXpathsEqual(controlXpath[i], xpathNodesControlXML, testXpath[i], xpathNodesTestXML); + assertXpathsEqual(controlXpath[i], + new InputSource(new StringReader(xpathNodesControlXML)), + testXpath[i], + new InputSource(new StringReader(xpathNodesTestXML))); assertXpathsEqual(controlXpath[i], testXpath[i], controlDoc); assertXpathsEqual(controlXpath[i], testXpath[i], xpathNodesControlXML); } @@ -376,6 +599,14 @@ } catch (AssertionFailedError e) { } try { + assertXpathsNotEqual(controlXpath[i], + new InputSource(new StringReader(xpathNodesControlXML)), + testXpath[i], + new InputSource(new StringReader(xpathNodesTestXML))); + fail("should not be notEqual!"); + } catch (AssertionFailedError e) { + } + try { assertXpathsNotEqual(controlXpath[i], testXpath[i], controlDoc); fail("should not be notEqual!"); } catch (AssertionFailedError e) { @@ -460,6 +691,20 @@ } } + public void testInputSourceAssertXpathExists() throws Exception { + assertXpathExists("/trees/fruit/apples/yum", + new InputSource(new StringReader(xpathNodesControlXML))); + assertXpathExists("//tree[@evergreen='false']", + new InputSource(new StringReader(xpathNodesControlXML))); + try { + assertXpathExists("//tree[@evergreen='idunno']", + new InputSource(new StringReader(xpathNodesControlXML))); + fail("Xpath does not exist"); + } catch (AssertionFailedError e) { + // expected + } + } + public void testDocumentAssertNotXpathExists() throws Exception { Document controlDoc = XMLUnit.buildControlDocument(xpathNodesControlXML); assertXpathNotExists("//tree[@evergreen='idunno']", controlDoc); @@ -493,6 +738,25 @@ } } + public void testInputSourceAssertNotXpathExists() throws Exception { + assertXpathNotExists("//tree[@evergreen='idunno']", + new InputSource(new StringReader(xpathNodesControlXML))); + try { + assertXpathNotExists("/trees/fruit/apples/yum", + new InputSource(new StringReader(xpathNodesControlXML))); + fail("Xpath does exist, once"); + } catch (AssertionFailedError e) { + // expected + } + try { + assertXpathNotExists("//tree[@evergreen='false']", + new InputSource(new StringReader(xpathNodesControlXML))); + fail("Xpath does exist many times"); + } catch (AssertionFailedError e) { + // expected + } + } + // Bug 585555 public void testUnusedNamespacesDontMatter() throws Exception { @@ -583,6 +847,15 @@ "<foo><Bar a=\"1\" b=\"2\"/></foo>"); } + public void testAssertXpathEqualsInputSource() throws Exception { + InputSource control = new InputSource(new StringReader("<foo><Bar a=\"1\" /></foo>")); + assertXpathsNotEqual("/foo/Bar/@a", "/foo/Bar", control); + control = new InputSource(new StringReader("<foo><Bar a=\"1\" b=\"1\"/></foo>")); + assertXpathsNotEqual("/foo/Bar/@a", "/foo/Bar/@b", control); + control = new InputSource(new StringReader("<foo><Bar a=\"1\" b=\"2\"/></foo>")); + assertXpathsEqual("/foo/Bar/@a", "/foo/Bar/@a", control); + } + // https://sourceforge.net/p/xmlunit/feature-requests/25/ public void testXpathEvaluatesToQualifiedName() throws Exception { String faultDocument = "<env:Envelope " @@ -599,10 +872,6 @@ faultDocument); } - public test_XMLTestCase(String name) { - super(name); - } - private static String addNamespaceToDocument(String original) { int pos = original.indexOf(">"); return original.substring(0, pos) + " xmlns='" + TEST_NS + "'" Modified: trunk/tests/java/org/custommonkey/xmlunit/test_XMLUnit.java =================================================================== --- trunk/tests/java/org/custommonkey/xmlunit/test_XMLUnit.java 2015-01-13 19:42:26 UTC (rev 592) +++ trunk/tests/java/org/custommonkey/xmlunit/test_XMLUnit.java 2015-03-08 05:59:53 UTC (rev 593) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007,2015 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -135,4 +135,24 @@ XMLUnit.setXSLTVersion("1.0"); } } + + public void testCantSetNullControlDocumentBuilderFactory() throws Exception { + try { + XMLUnit.setControlDocumentBuilderFactory(null); + fail("should have thrown an exception"); + } catch (IllegalArgumentException f) { + // expected + return; + } + } + + public void testCantSetNullTestDocumentBuilderFactory() throws Exception { + try { + XMLUnit.setTestDocumentBuilderFactory(null); + fail("should have thrown an exception"); + } catch (IllegalArgumentException f) { + // expected + return; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |