[DOXIA-514] Prepare unittests for JDK8
Validate XML by using XMLUnit
git-svn-id: https://svn.apache.org/repos/asf/maven/doxia/doxia/trunk@1563713 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/doxia-core/pom.xml b/doxia-core/pom.xml
index a22979f..9c63d45 100644
--- a/doxia-core/pom.xml
+++ b/doxia-core/pom.xml
@@ -76,6 +76,12 @@
</dependency>
<!-- test -->
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.5</version>
+ </dependency>
+
</dependencies>
<build>
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java
index c005718..eca3e65 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java
@@ -26,6 +26,8 @@
import org.apache.maven.doxia.AbstractModuleTest;
import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
import org.codehaus.plexus.util.IOUtil;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
/**
* Abstract base class to test sinks.
@@ -57,6 +59,17 @@
sink.enableLogging( new PlexusLoggerWrapper( getContainer().getLogger() ) );
}
+ /**
+ * Ability to wrap the xmlFragment with a roottag and namespaces, when required
+ *
+ * @param xmlFragment
+ * @return valid XML
+ */
+ protected String wrapXml( String xmlFragment )
+ {
+ return xmlFragment;
+ }
+
// ---------------------------------------------------------------------
// Common test cases
// ----------------------------------------------------------------------
@@ -405,7 +418,7 @@
* invoked on the current sink, produces the same result as
* {@link #getFigureBlock getFigureBlock}( source, caption ).
*/
- public void testFigure()
+ public void testFigure() throws Exception
{
String source = "figure.jpg";
String caption = "Figure_caption";
@@ -421,11 +434,19 @@
String actual = testWriter.toString();
String expected = getFigureBlock( source, caption );
- assertEquals( "Wrong figure!", expected, actual );
+ if ( isXmlSink() )
+ {
+ Diff diff = XMLUnit.compareXML( wrapXml( expected ), wrapXml( actual ) );
+ assertTrue( "Wrong figure!", diff.identical() );
+ }
+ else
+ {
+ assertEquals( "Wrong figure!", expected, actual );
+ }
}
- public void testFigureWithoutCaption()
+ public void testFigureWithoutCaption() throws Exception
{
String source = "figure.jpg";
sink.figure();
@@ -437,8 +458,15 @@
String actual = testWriter.toString();
String expected = getFigureBlock( source, null );
- assertEquals( "Wrong figure!", expected, actual );
-
+ if ( isXmlSink() )
+ {
+ Diff diff = XMLUnit.compareXML( wrapXml( expected ), wrapXml( actual ) );
+ assertTrue( "Wrong figure!", diff.identical() );
+ }
+ else
+ {
+ assertEquals( "Wrong figure!", expected, actual );
+ }
}
/**
@@ -449,7 +477,7 @@
* invoked on the current sink, produces the same result as
* {@link #getTableBlock getTableBlock}( cell, caption ).
*/
- public void testTable()
+ public void testTable() throws Exception
{
String cell = "cell";
String caption = "Table_caption";
@@ -472,7 +500,15 @@
String actual = testWriter.toString();
String expected = getTableBlock( cell, caption );
- assertEquals( "Wrong table!", expected, actual );
+ if ( isXmlSink() )
+ {
+ Diff diff = XMLUnit.compareXML( wrapXml( expected ), wrapXml( actual ) );
+ assertTrue( "Wrong table!", diff.identical() );
+ }
+ else
+ {
+ assertEquals( "Wrong table!", expected, actual );
+ }
}
/**
diff --git a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
index 4b5afaa..bd07c7d 100644
--- a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
+++ b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
@@ -28,7 +28,10 @@
import org.apache.maven.doxia.document.DocumentCover;
import org.apache.maven.doxia.document.DocumentModel;
+import org.apache.maven.doxia.markup.Markup;
import org.codehaus.plexus.util.WriterFactory;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
import org.xml.sax.SAXParseException;
import junit.framework.TestCase;
@@ -53,6 +56,12 @@
super.setUp();
writer = new StringWriter();
}
+
+ protected String wrapXml( String xmlFragment )
+ {
+ return "<fo:fo xmlns:fo=\"" + FoMarkup.FO_NAMESPACE+ "\">" + xmlFragment + "</fo:fo>";
+ }
+
/**
* Test of body method, of class FoAggregateSink.
@@ -155,7 +164,7 @@
/**
* Test of figureGraphics method, of class FoAggregateSink.
*/
- public void testFigureGraphics()
+ public void testFigureGraphics() throws Exception
{
try
{
@@ -168,7 +177,15 @@
sink.close();
}
- assertTrue( writer.toString().indexOf( "<fo:external-graphic src=\"./images/fig.png\"" ) != -1 );
+ String expected = "<fo:external-graphic src=\"./images/fig.png\" "
+ + "content-width=\"scale-down-to-fit\" "
+ + "content-height=\"scale-down-to-fit\" "
+ + "height=\"100%\" "
+ + "width=\"100%\"/>" + Markup.EOL;
+ String actual = writer.toString();
+
+ Diff diff = XMLUnit.compareXML( wrapXml( expected ), wrapXml( actual ) );
+ assertTrue( "Wrong figure!", diff.identical() );
}
/**
diff --git a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
index 67b7a60..512fd51 100644
--- a/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
+++ b/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
@@ -27,12 +27,10 @@
import org.apache.maven.doxia.document.DocumentModel;
import org.apache.maven.doxia.document.DocumentTOC;
import org.apache.maven.doxia.document.DocumentTOCItem;
-
import org.apache.maven.doxia.parser.XhtmlBaseParser;
-import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.AbstractSinkTest;
+import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkTestDocument;
-import org.codehaus.plexus.util.StringUtils;
/**
* <code>FO Sink</code> Test case.
@@ -48,6 +46,12 @@
// Specific test methods
// ----------------------------------------------------------------------
+ @Override
+ protected String wrapXml( String xmlFragment )
+ {
+ return "<fo:fo xmlns:fo=\"" + FoMarkup.FO_NAMESPACE + "\">" + xmlFragment + "</fo:fo>";
+ }
+
/**
* Uses fop to generate a pdf from a test document.
* @throws Exception If the conversion fails.