Author: britter
Date: Mon Jan 12 19:01:50 2015
New Revision: 1651164
URL: http://svn.apache.org/r1651164
Log:
Make IptcUpdateTest a parameterized test (extracted testing of add
functionality into a separate test for this purpose)
Added:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
(with props)
Modified:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBaseTest.java
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
Added:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java?rev=1651164&view=auto
==============================================================================
---
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
(added)
+++
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
Mon Jan 12 19:01:50 2015
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.imaging.formats.jpeg.iptc;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+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.formats.jpeg.JpegPhotoshopMetadata;
+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 IptcAddTest extends IptcBaseTest {
+
+ private File imageFile;
+
+ @Parameterized.Parameters
+ public static Collection<File> data() throws Exception {
+ return getJpegImages();
+ }
+
+ public IptcAddTest(File imageFile) {
+ this.imageFile = imageFile;
+ }
+
+ /*
+ * Add a few IPTC values to JPEG images, whether or not they have
existing
+ * IPTC data.
+ */
+ @Test
+ public void testAddIptcData() throws Exception {
+ final ByteSource byteSource = new ByteSourceFile(imageFile);
+
+ final Map<String, Object> params = new HashMap<String, Object>();
+ final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params.put(PARAM_KEY_READ_THUMBNAILS,
Boolean.valueOf(!ignoreImageData));
+
+ final JpegPhotoshopMetadata metadata = new
JpegImageParser().getPhotoshopMetadata(byteSource, params);
+
+ {
+ final List<IptcBlock> newBlocks = new ArrayList<IptcBlock>();
+ List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
+
+ if (null != metadata) {
+ final boolean keepOldIptcNonTextValues = true;
+ if (keepOldIptcNonTextValues) {
+ newBlocks.addAll(metadata.photoshopApp13Data
+ .getNonIptcBlocks());
+ }
+ final boolean keepOldIptcTextValues = true;
+ if (keepOldIptcTextValues) {
+ final List<IptcRecord> oldRecords =
metadata.photoshopApp13Data
+ .getRecords();
+
+ newRecords = new ArrayList<IptcRecord>();
+ for (int j = 0; j < oldRecords.size(); j++) {
+ final IptcRecord record = oldRecords.get(j);
+ if (record.iptcType != IptcTypes.CITY
+ && record.iptcType != IptcTypes.CREDIT) {
+ newRecords.add(record);
+ }
+ }
+ }
+ }
+
+ newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
+ newRecords.add(new IptcRecord(IptcTypes.CREDIT,
+ "William Sorensen"));
+
+ final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
+ newBlocks);
+
+ final File updated = createTempFile(imageFile.getName()
+ + ".iptc.add.", ".jpg");
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ // Debug.debug("Destination Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ final ByteSource updateByteSource = new ByteSourceFile(updated);
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
+
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
+
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == newRecords.size());
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
+ }
+}
Propchange:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcAddTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBaseTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBaseTest.java?rev=1651164&r1=1651163&r2=1651164&view=diff
==============================================================================
---
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBaseTest.java
(original)
+++
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcBaseTest.java
Mon Jan 12 19:01:50 2015
@@ -80,7 +80,7 @@ public abstract class IptcBaseTest exten
return getTestImage(JPEG_IMAGE_FILTER);
}
- protected List<File> getJpegImages() throws IOException,
ImageReadException {
+ protected static List<File> getJpegImages() throws IOException,
ImageReadException {
return getTestImages(JPEG_IMAGE_FILTER);
}
Modified:
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java?rev=1651164&r1=1651163&r2=1651164&view=diff
==============================================================================
---
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
(original)
+++
commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/jpeg/iptc/IptcUpdateTest.java
Mon Jan 12 19:01:50 2015
@@ -25,6 +25,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -38,18 +39,20 @@ import org.apache.commons.imaging.util.I
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+@RunWith(Parameterized.class)
public class IptcUpdateTest extends IptcBaseTest {
- private List<File> imagesWithIptcData;
+ private File imageFile;
- @Before
- public void setUp() throws Exception {
- imagesWithIptcData = getImagesWithIptcData();
+ @Parameterized.Parameters
+ public static Collection<File> data() throws Exception {
+ return getImagesWithIptcData();
}
- @After
- public void tearDown() throws Exception {
- imagesWithIptcData = null;
+ public IptcUpdateTest(File imageFile) {
+ this.imageFile = imageFile;
}
/*
@@ -57,325 +60,218 @@ public class IptcUpdateTest extends Iptc
*/
@Test
public void testRemove() throws Exception {
- final List<File> images = imagesWithIptcData;
- for (int i = 0; i < images.size(); i++) {
-
- 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 boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params.put(PARAM_KEY_READ_THUMBNAILS, new
Boolean(!ignoreImageData));
-
- final JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- assertNotNull(metadata);
- // metadata.dump();
-
- final File noIptcFile = createTempFile(imageFile.getName()
- + ".iptc.remove.", ".jpg");
- {
- // test remove
-
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(noIptcFile);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().removeIPTC(byteSource, os);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
- }
-
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
- params);
- assertTrue(outMetadata == null
- || outMetadata.getItems().size() == 0);
- }
+ final ByteSource byteSource = new ByteSourceFile(imageFile);
+ final Map<String, Object> params = new HashMap<String, Object>();
+ final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+
+ final JpegPhotoshopMetadata metadata = new JpegImageParser()
+ .getPhotoshopMetadata(byteSource, params);
+ assertNotNull(metadata);
+ // metadata.dump();
+
+ final File noIptcFile = createTempFile(imageFile.getName()
+ + ".iptc.remove.", ".jpg");
+ {
+ // test remove
+
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(noIptcFile);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().removeIPTC(byteSource, os);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+ params);
+ assertTrue(outMetadata == null
+ || outMetadata.getItems().size() == 0);
}
}
@Test
public void testRemoveInsertUpdate() throws Exception {
- final List<File> images = imagesWithIptcData;
- for (int i = 0; i < images.size(); i++) {
-
- final File imageFile = images.get(i);
- Debug.debug("imageFile", imageFile);
- Debug.debug();
-
- final ByteSource byteSource = new ByteSourceFile(imageFile);
- // Debug.debug("Segments:");
- // new JpegUtils().dumpJFIF(byteSource);
-
- final Map<String, Object> params = new HashMap<String, Object>();
- final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params.put(PARAM_KEY_READ_THUMBNAILS, new
Boolean(!ignoreImageData));
- // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
- // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
-
- final JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- assertNotNull(metadata);
- metadata.dump();
-
- final File noIptcFile = createTempFile(imageFile.getName()
- + ".iptc.remove.", ".jpg");
- {
- // test remove
-
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(noIptcFile);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().removeIPTC(byteSource, os);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
- }
-
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
-
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
- params);
- assertTrue(outMetadata == null
- || outMetadata.getItems().size() == 0);
- }
- {
- // test no-change update
-
- final List<IptcBlock> newBlocks =
metadata.photoshopApp13Data.getNonIptcBlocks();
- final List<IptcRecord> oldRecords =
metadata.photoshopApp13Data.getRecords();
- final List<IptcRecord> newRecords = new
ArrayList<IptcRecord>();
- for (int j = 0; j < oldRecords.size(); j++) {
- final IptcRecord record = oldRecords.get(j);
- if (record.iptcType != IptcTypes.CITY
- && record.iptcType != IptcTypes.CREDIT) {
- newRecords.add(record);
- }
- }
-
- newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
- newRecords.add(new IptcRecord(IptcTypes.CREDIT,
- "William Sorensen"));
-
- final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
- newBlocks);
-
- final File updated = createTempFile(imageFile.getName()
- + ".iptc.update.", ".jpg");
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
- }
-
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
-
- final ByteSource updateByteSource = new
ByteSourceFile(updated);
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
-
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
-
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == newRecords.size());
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
-
- {
- // test update
-
- final List<IptcBlock> newBlocks =
metadata.photoshopApp13Data.getNonIptcBlocks();
- final List<IptcRecord> newRecords = new
ArrayList<IptcRecord>();
+ final ByteSource byteSource = new ByteSourceFile(imageFile);
+ // Debug.debug("Segments:");
+ // new JpegUtils().dumpJFIF(byteSource);
+
+ final Map<String, Object> params = new HashMap<String, Object>();
+ final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+ params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+ // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+ // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+ final JpegPhotoshopMetadata metadata = new JpegImageParser()
+ .getPhotoshopMetadata(byteSource, params);
+ assertNotNull(metadata);
+ metadata.dump();
+
+ final File noIptcFile = createTempFile(imageFile.getName()
+ + ".iptc.remove.", ".jpg");
+ {
+ // test remove
+
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(noIptcFile);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().removeIPTC(byteSource, os);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
+
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+ params);
+ assertTrue(outMetadata == null
+ || outMetadata.getItems().size() == 0);
+ }
+ {
+ // test no-change update
- newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
- newRecords.add(new IptcRecord(IptcTypes.CREDIT,
- "William Sorensen"));
-
- final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
- newBlocks);
-
- final File updated = createTempFile(imageFile.getName()
- + ".iptc.update.", ".jpg");
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
+ final List<IptcBlock> newBlocks =
metadata.photoshopApp13Data.getNonIptcBlocks();
+ final List<IptcRecord> oldRecords =
metadata.photoshopApp13Data.getRecords();
+ final List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
+ for (int j = 0; j < oldRecords.size(); j++) {
+ final IptcRecord record = oldRecords.get(j);
+ if (record.iptcType != IptcTypes.CITY
+ && record.iptcType != IptcTypes.CREDIT) {
+ newRecords.add(record);
}
-
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
-
- final ByteSource updateByteSource = new
ByteSourceFile(updated);
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
-
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
-
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == 2);
- // assertEquals(metadata.toString(), outMetadata.toString());
}
- {
- // test insert
-
- final List<IptcBlock> newBlocks = new ArrayList<IptcBlock>();
- final List<IptcRecord> newRecords = new
ArrayList<IptcRecord>();
-
- newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
- newRecords.add(new IptcRecord(IptcTypes.CREDIT,
- "William Sorensen"));
-
- final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
- newBlocks);
-
- final File updated = createTempFile(imageFile.getName()
- + ".iptc.insert.", ".jpg");
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
- noIptcFile), os, newData);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
- }
+ newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
+ newRecords.add(new IptcRecord(IptcTypes.CREDIT,
+ "William Sorensen"));
+
+ final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
+ newBlocks);
+
+ final File updated = createTempFile(imageFile.getName()
+ + ".iptc.update.", ".jpg");
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ final ByteSource updateByteSource = new ByteSourceFile(updated);
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
+
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
+
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == newRecords.size());
+ // assertEquals(metadata.toString(), outMetadata.toString());
+ }
- // Debug.debug("Source Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+ {
+ // test update
- final ByteSource updateByteSource = new
ByteSourceFile(updated);
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
-
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
-
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == 2);
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ final List<IptcBlock> newBlocks =
metadata.photoshopApp13Data.getNonIptcBlocks();
+ final List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
+ newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
+ newRecords.add(new IptcRecord(IptcTypes.CREDIT,
+ "William Sorensen"));
+
+ final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
+ newBlocks);
+
+ final File updated = createTempFile(imageFile.getName()
+ + ".iptc.update.", ".jpg");
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ final ByteSource updateByteSource = new ByteSourceFile(updated);
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
+
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
+
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == 2);
+ // assertEquals(metadata.toString(), outMetadata.toString());
}
- }
- /*
- * Add a few IPTC values to JPEG images, whether or not they have existing
- * IPTC data.
- */
- @Test
- public void testAddIptcData() throws Exception {
- final List<File> images = getJpegImages();
- for (int i = 0; i < images.size(); i++) {
-
- final File imageFile = images.get(i);
- // Debug.debug("imageFile", imageFile);
- // Debug.debug();
-
- final ByteSource byteSource = new ByteSourceFile(imageFile);
- // Debug.debug("Segments:");
- // new JpegUtils().dumpJFIF(byteSource);
-
- final Map<String, Object> params = new HashMap<String, Object>();
- final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
- params.put(PARAM_KEY_READ_THUMBNAILS, new
Boolean(!ignoreImageData));
-
- final JpegPhotoshopMetadata metadata = new JpegImageParser()
- .getPhotoshopMetadata(byteSource, params);
- // metadata.dump();
-
- {
- final List<IptcBlock> newBlocks = new ArrayList<IptcBlock>();
- List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
-
- if (null != metadata) {
- final boolean keepOldIptcNonTextValues = true;
- if (keepOldIptcNonTextValues) {
- newBlocks.addAll(metadata.photoshopApp13Data
- .getNonIptcBlocks());
- }
- final boolean keepOldIptcTextValues = true;
- if (keepOldIptcTextValues) {
- final List<IptcRecord> oldRecords =
metadata.photoshopApp13Data
- .getRecords();
-
- newRecords = new ArrayList<IptcRecord>();
- for (int j = 0; j < oldRecords.size(); j++) {
- final IptcRecord record = oldRecords.get(j);
- if (record.iptcType != IptcTypes.CITY
- && record.iptcType != IptcTypes.CREDIT) {
- newRecords.add(record);
- }
- }
- }
- }
+ {
+ // test insert
- newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
- newRecords.add(new IptcRecord(IptcTypes.CREDIT,
- "William Sorensen"));
-
- final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
- newBlocks);
-
- final File updated = createTempFile(imageFile.getName()
- + ".iptc.add.", ".jpg");
- OutputStream os = null;
- boolean canThrow = false;
- try {
- os = new FileOutputStream(updated);
- os = new BufferedOutputStream(os);
- new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
- canThrow = true;
- } finally {
- IoUtils.closeQuietly(canThrow, os);
- }
-
- // Debug.debug("Destination Segments:");
- // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
-
- final ByteSource updateByteSource = new
ByteSourceFile(updated);
- final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
- .getPhotoshopMetadata(updateByteSource, params);
-
- // Debug.debug("outMetadata", outMetadata.toString());
- // Debug.debug("hasIptcSegment", new JpegImageParser()
- // .hasIptcSegment(updateByteSource));
-
- assertNotNull(outMetadata);
- assertTrue(outMetadata.getItems().size() == newRecords.size());
- // assertEquals(metadata.toString(), outMetadata.toString());
- }
+ final List<IptcBlock> newBlocks = new ArrayList<IptcBlock>();
+ final List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
+ newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
+ newRecords.add(new IptcRecord(IptcTypes.CREDIT,
+ "William Sorensen"));
+
+ final PhotoshopApp13Data newData = new
PhotoshopApp13Data(newRecords,
+ newBlocks);
+
+ final File updated = createTempFile(imageFile.getName()
+ + ".iptc.insert.", ".jpg");
+ OutputStream os = null;
+ boolean canThrow = false;
+ try {
+ os = new FileOutputStream(updated);
+ os = new BufferedOutputStream(os);
+ new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
+ noIptcFile), os, newData);
+ canThrow = true;
+ } finally {
+ IoUtils.closeQuietly(canThrow, os);
+ }
+
+ // Debug.debug("Source Segments:");
+ // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+ final ByteSource updateByteSource = new ByteSourceFile(updated);
+ final JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+ .getPhotoshopMetadata(updateByteSource, params);
+
+ // Debug.debug("outMetadata", outMetadata.toString());
+ // Debug.debug("hasIptcSegment", new JpegImageParser()
+ // .hasIptcSegment(updateByteSource));
+
+ assertNotNull(outMetadata);
+ assertTrue(outMetadata.getItems().size() == 2);
+ // assertEquals(metadata.toString(), outMetadata.toString());
}
+
}
}