Author: britter Date: Mon Jan 12 19:42:15 2015 New Revision: 1651180 URL: http://svn.apache.org/r1651180 Log: Make JpegXmp tests parameterized tests
Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpBaseTest.java commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpBaseTest.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpBaseTest.java?rev=1651180&r1=1651179&r2=1651180&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpBaseTest.java (original) +++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpBaseTest.java Mon Jan 12 19:42:15 2015 @@ -68,7 +68,7 @@ public abstract class JpegXmpBaseTest ex return getTestImage(HAS_JPEG_XMP_IMAGE_FILTER); } - protected List<File> getImagesWithXmpData() throws IOException, + protected static List<File> getImagesWithXmpData() throws IOException, ImageReadException { return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER); } Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java?rev=1651180&r1=1651179&r2=1651180&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java (original) +++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpDumpTest.java Mon Jan 12 19:42:15 2015 @@ -20,35 +20,39 @@ package org.apache.commons.imaging.forma import static org.junit.Assert.assertNotNull; import java.io.File; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; -import org.apache.commons.imaging.util.Debug; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class JpegXmpDumpTest extends JpegXmpBaseTest { + private File imageFile; + + @Parameterized.Parameters + public static Collection<File> data() throws Exception { + return getImagesWithXmpData(); + } + + public JpegXmpDumpTest(File imageFile) { + this.imageFile = imageFile; + } + @Test public void test() throws Exception { - final List<File> images = getImagesWithXmpData(); - for (int i = 0; i < images.size(); i++) { + final ByteSource byteSource = new ByteSourceFile(imageFile); + final Map<String, Object> params = new HashMap<String, Object>(); + final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); - final File imageFile = images.get(i); - Debug.debug("imageFile", imageFile); - Debug.debug(); - - final ByteSource byteSource = new ByteSourceFile(imageFile); - final Map<String, Object> params = new HashMap<String, Object>(); - final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); - assertNotNull(xmpXml); - - Debug.debug("xmpXml: " + xmpXml); - Debug.debug(); - } + // TODO assert more + assertNotNull(xmpXml); } } Modified: commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java URL: http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java?rev=1651180&r1=1651179&r2=1651180&view=diff ============================================================================== --- commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java (original) +++ commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriteTest.java Mon Jan 12 19:42:15 2015 @@ -25,116 +25,112 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.commons.imaging.common.bytesource.ByteSource; import org.apache.commons.imaging.common.bytesource.ByteSourceFile; import org.apache.commons.imaging.formats.jpeg.JpegImageParser; -import org.apache.commons.imaging.util.Debug; import org.apache.commons.imaging.util.IoUtils; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class JpegXmpRewriteTest extends JpegXmpBaseTest { + private File imageFile; + + @Parameterized.Parameters + public static Collection<File> data() throws Exception { + return getImagesWithXmpData(); + } + + public JpegXmpRewriteTest(File imageFile) { + this.imageFile = imageFile; + } + @Test public void testRemoveInsertUpdate() throws Exception { - final List<File> images = getImagesWithXmpData(); - for (int i = 0; i < images.size(); i++) { + final ByteSource byteSource = new ByteSourceFile(imageFile); + final Map<String, Object> params = new HashMap<String, Object>(); + final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); + assertNotNull(xmpXml); + + final File noXmpFile = createTempFile(imageFile.getName() + ".", ".jpg"); + { + // test remove + + OutputStream os = null; + boolean canThrow = false; + try { + os = new FileOutputStream(noXmpFile); + os = new BufferedOutputStream(os); + new JpegXmpRewriter().removeXmpXml(byteSource, os); + canThrow = true; + } finally { + IoUtils.closeQuietly(canThrow, os); + } - final File imageFile = images.get(i); - Debug.debug("imageFile", imageFile); + // Debug.debug("Source Segments:"); + // new JpegUtils().dumpJFIF(new ByteSourceFile(noXmpFile)); - // boolean ignoreImageData = isPhilHarveyTestImage(imageFile); - // if (ignoreImageData) - // continue; + final String outXmp = new JpegImageParser().getXmpXml( + new ByteSourceFile(noXmpFile), params); + assertNull(outXmp); + } - final ByteSource byteSource = new ByteSourceFile(imageFile); - // Debug.debug("Source Segments:"); - // new JpegUtils().dumpJFIF(byteSource); + { + // test update - final Map<String, Object> params = new HashMap<String, Object>(); - final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params); - assertNotNull(xmpXml); - - // Debug.debug("xmpXml", xmpXml.length()); - // Debug.debug(); - - final File noXmpFile = createTempFile(imageFile.getName() + ".", ".jpg"); - { - // test remove - - OutputStream os = null; - boolean canThrow = false; - try { - os = new FileOutputStream(noXmpFile); - os = new BufferedOutputStream(os); - new JpegXmpRewriter().removeXmpXml(byteSource, os); - canThrow = true; - } finally { - IoUtils.closeQuietly(canThrow, os); - } - - // Debug.debug("Source Segments:"); - // new JpegUtils().dumpJFIF(new ByteSourceFile(noXmpFile)); - - final String outXmp = new JpegImageParser().getXmpXml( - new ByteSourceFile(noXmpFile), params); - assertNull(outXmp); + final String newXmpXml = "test"; + final File updated = createTempFile(imageFile.getName() + ".", ".jpg"); + OutputStream os = null; + boolean canThrow = false; + try { + os = new FileOutputStream(updated); + os = new BufferedOutputStream(os); + new JpegXmpRewriter().updateXmpXml(byteSource, os, + newXmpXml); + canThrow = true; + } finally { + IoUtils.closeQuietly(canThrow, os); } - { - // test update + // Debug.debug("Source Segments:"); + // new JpegUtils().dumpJFIF(new ByteSourceFile(updated)); - final String newXmpXml = "test"; - final File updated = createTempFile(imageFile.getName() + ".", ".jpg"); - OutputStream os = null; - boolean canThrow = false; - try { - os = new FileOutputStream(updated); - os = new BufferedOutputStream(os); - new JpegXmpRewriter().updateXmpXml(byteSource, os, - newXmpXml); - canThrow = true; - } finally { - IoUtils.closeQuietly(canThrow, os); - } - - // Debug.debug("Source Segments:"); - // new JpegUtils().dumpJFIF(new ByteSourceFile(updated)); - - final String outXmp = new JpegImageParser().getXmpXml( - new ByteSourceFile(updated), params); - assertNotNull(outXmp); - assertEquals(outXmp, newXmpXml); - } + final String outXmp = new JpegImageParser().getXmpXml( + new ByteSourceFile(updated), params); + assertNotNull(outXmp); + assertEquals(outXmp, newXmpXml); + } - { - // test insert + { + // test insert - final String newXmpXml = "test"; - final File updated = createTempFile(imageFile.getName() + ".", ".jpg"); - OutputStream os = null; - boolean canThrow = false; - try { - os = new FileOutputStream(updated); - os = new BufferedOutputStream(os); - new JpegXmpRewriter().updateXmpXml(new ByteSourceFile( - noXmpFile), os, newXmpXml); - canThrow = true; - } finally { - IoUtils.closeQuietly(canThrow, os); - } - - // Debug.debug("Source Segments:"); - // new JpegUtils().dumpJFIF(new ByteSourceFile(updated)); - - final String outXmp = new JpegImageParser().getXmpXml( - new ByteSourceFile(updated), params); - assertNotNull(outXmp); - assertEquals(outXmp, newXmpXml); + final String newXmpXml = "test"; + final File updated = createTempFile(imageFile.getName() + ".", ".jpg"); + OutputStream os = null; + boolean canThrow = false; + try { + os = new FileOutputStream(updated); + os = new BufferedOutputStream(os); + new JpegXmpRewriter().updateXmpXml(new ByteSourceFile( + noXmpFile), os, newXmpXml); + canThrow = true; + } finally { + IoUtils.closeQuietly(canThrow, os); } + + // Debug.debug("Source Segments:"); + // new JpegUtils().dumpJFIF(new ByteSourceFile(updated)); + + final String outXmp = new JpegImageParser().getXmpXml( + new ByteSourceFile(updated), params); + assertNotNull(outXmp); + assertEquals(outXmp, newXmpXml); } }