You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2014/02/02 21:55:04 UTC

svn commit: r1563713 - in /maven/doxia/doxia/trunk: doxia-core/ doxia-core/src/test/java/org/apache/maven/doxia/sink/ doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/

Author: rfscholte
Date: Sun Feb  2 20:55:04 2014
New Revision: 1563713

URL: http://svn.apache.org/r1563713
Log:
[DOXIA-514] Prepare unittests for JDK8
Validate XML by using XMLUnit

Modified:
    maven/doxia/doxia/trunk/doxia-core/pom.xml
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java

Modified: maven/doxia/doxia/trunk/doxia-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/pom.xml?rev=1563713&r1=1563712&r2=1563713&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/pom.xml (original)
+++ maven/doxia/doxia/trunk/doxia-core/pom.xml Sun Feb  2 20:55:04 2014
@@ -76,6 +76,12 @@ under the License.
     </dependency>
 
     <!-- test -->
+    <dependency>
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <version>1.5</version>
+    </dependency>
+
   </dependencies>
 
   <build>

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java?rev=1563713&r1=1563712&r2=1563713&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/AbstractSinkTest.java Sun Feb  2 20:55:04 2014
@@ -26,6 +26,8 @@ import java.io.Writer;
 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 @@ public abstract class AbstractSinkTest
         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 @@ public abstract class AbstractSinkTest
      * 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 @@ public abstract class AbstractSinkTest
         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 @@ public abstract class AbstractSinkTest
         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 @@ public abstract class AbstractSinkTest
      * 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 @@ public abstract class AbstractSinkTest
         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 );
+        }
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java?rev=1563713&r1=1563712&r2=1563713&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoAggregateSinkTest.java Sun Feb  2 20:55:04 2014
@@ -28,7 +28,10 @@ import javax.xml.transform.TransformerEx
 
 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 @@ public class FoAggregateSinkTest
         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 @@ public class FoAggregateSinkTest
     /**
      * Test of figureGraphics method, of class FoAggregateSink.
      */
-    public void testFigureGraphics()
+    public void testFigureGraphics() throws Exception
     {
         try
         {
@@ -168,7 +177,15 @@ public class FoAggregateSinkTest
             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() );
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java?rev=1563713&r1=1563712&r2=1563713&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java Sun Feb  2 20:55:04 2014
@@ -27,12 +27,10 @@ import org.apache.maven.doxia.document.D
 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 @@ public class FoSinkTest
     // 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.