Skip to content

Commit

Permalink
upgrade jhove from 1.11.0 to 1.20.1, add tests IQSS#2202
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed May 2, 2019
1 parent 82cea9a commit d9e7d71
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 50 deletions.
4 changes: 4 additions & 0 deletions conf/jhove/jhove.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@
<module>
<class>edu.harvard.hul.ois.jhove.module.Utf8Module</class>
</module>
<module>
<!-- https://github.com/openpreserve/jhove/blob/v1.20.1/jhove-ext-modules/src/main/java/com/mcgath/jhove/module/PngModule.java#L1 -->
<class>com.mcgath.jhove.module.PngModule</class>
</module>
</jhoveConfig>
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 10 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<junit.platform.version>1.3.1</junit.platform.version>
<mockito.version>2.22.0</mockito.version>
<flyway.version>5.2.4</flyway.version>
<jhove.version>1.20.1</jhove.version>
<!--
Jacoco 0.8.2 seems to break Netbeans code coverage integration so we'll use 0.8.1 instead.
See https://github.com/jacoco/jacoco/issues/772 for discussion of how the XML changed.
Expand Down Expand Up @@ -376,19 +377,19 @@
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>edu.harvard.hul.ois.jhove</groupId>
<artifactId>jhove</artifactId>
<version>1.11.0</version>
<groupId>org.openpreservation.jhove</groupId>
<artifactId>jhove-core</artifactId>
<version>${jhove.version}</version>
</dependency>
<dependency>
<groupId>edu.harvard.hul.ois.jhove</groupId>
<artifactId>jhove-module</artifactId>
<version>1.11.0</version>
<groupId>org.openpreservation.jhove</groupId>
<artifactId>jhove-modules</artifactId>
<version>${jhove.version}</version>
</dependency>
<dependency>
<groupId>edu.harvard.hul.ois.jhove</groupId>
<artifactId>jhove-handler</artifactId>
<version>1.11.0</version>
<groupId>org.openpreservation.jhove</groupId>
<artifactId>jhove-ext-modules</artifactId>
<version>${jhove.version}</version>
</dependency>
<!-- JAI (Java Advanced Imaging) jars: -->
<dependency>
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/util/JhoveFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
*/
package edu.harvard.iq.dataverse.util;

import edu.harvard.hul.ois.jhove.*;
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import edu.harvard.hul.ois.jhove.App;
import edu.harvard.hul.ois.jhove.JhoveBase;
import edu.harvard.hul.ois.jhove.Module;
import edu.harvard.hul.ois.jhove.RepInfo;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -69,7 +73,8 @@ public RepInfo checkFileType(File file) {
try {
// initialize the application spec object
// name, release number, build date, usage, Copyright infor
App jhoveApp = new App("Jhove", "1.11",
// TODO: Should the release number come from pom.xml as we upgrade from 1.11.0 to 1.20.1?
App jhoveApp = new App("Jhove", "1.20.1",
ORIGINAL_RELEASE_DATE, "Java JhoveFileType",
ORIGINAL_COPR_RIGHTS);

Expand Down
80 changes: 80 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/util/JhoveFileTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package edu.harvard.iq.dataverse.util;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;

public class JhoveFileTypeTest {

static JhoveFileType jhoveFileType;
static String baseDirForConfigFiles = "/tmp";
static File png;
static File gif;
static File jpg;
static File pdf;
static File zip;
static File xml;
static File html;
static File ico;

@BeforeClass
public static void setUpClass() {
jhoveFileType = new JhoveFileType();
copyConfigIntoPlace();

png = new File("src/test/resources/images/coffeeshop.png");
gif = new File("src/main/webapp/resources/images/ajax-loading.gif");
jpg = new File("src/main/webapp/resources/images/dataverseproject_logo.jpg");
pdf = new File("scripts/issues/1380/dvs.pdf");
zip = new File("src/test/resources/doi-10-5072-fk2hyixmyv1.0.zip");
xml = new File("pom.xml");
html = new File("src/main/webapp/mydata_templates/mydata.html");
ico = new File("src/main/webapp/resources/images/fav/favicon.ico");
}

@Test
public void testGetFileMimeType() {
System.out.println("getFileMimeType");
// GOOD: figured it out. :)
assertEquals("image/png", jhoveFileType.getFileMimeType(png));
assertEquals("image/gif", jhoveFileType.getFileMimeType(gif));
assertEquals("image/jpeg", jhoveFileType.getFileMimeType(jpg));
assertEquals("application/pdf", jhoveFileType.getFileMimeType(pdf));
// BAD: couldn't figure it out. :(
assertEquals("application/octet-stream", jhoveFileType.getFileMimeType(zip));
assertEquals("application/octet-stream", jhoveFileType.getFileMimeType(ico));
// BAD: not very specific. :(
assertEquals("text/plain; charset=US-ASCII", jhoveFileType.getFileMimeType(xml));
assertEquals("text/plain; charset=US-ASCII", jhoveFileType.getFileMimeType(html));
}

@Test
public void testCheckFileType() {
System.out.println("checkFileType");
jhoveFileType = new JhoveFileType();
assertEquals(543938, jhoveFileType.checkFileType(png).getSize());
}

@Test
public void testGetJhoveConfigFile() {
System.out.println("getJhoveConfigFile");
assertEquals(baseDirForConfigFiles + "/config/jhove.conf", JhoveFileType.getJhoveConfigFile());
}

private static void copyConfigIntoPlace() {
String testFile1Src = "conf/jhove/jhove.conf";
System.setProperty("com.sun.aas.instanceRoot", baseDirForConfigFiles);
String testFile1Tmp = baseDirForConfigFiles + "/config/jhove.conf";
try {
FileUtils.copyFile(new File(testFile1Src), new File(testFile1Tmp));
} catch (IOException ex) {
Logger.getLogger(JhoveFileTypeTest.class.getName()).log(Level.SEVERE, null, ex);
}
}

}

0 comments on commit d9e7d71

Please sign in to comment.