Adjust integration tests, fix compilation warnings, make the check on "EXPECTED_EXTRACTOR_FAILURES" actually work

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737242 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-03-31 13:56:27 +00:00
parent d0513f2ca6
commit 12f99cc9d5
4 changed files with 11 additions and 21 deletions

View File

@ -22,7 +22,6 @@ import static org.junit.Assert.assertNotNull;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashSet; import java.util.HashSet;
@ -32,7 +31,6 @@ import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor; import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor; import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
@ -52,9 +50,7 @@ public abstract class AbstractFileHandler implements FileHandler {
EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-simple.dat"); EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-simple.dat");
EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-with-attachments.dat"); EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-with-attachments.dat");
EXPECTED_EXTRACTOR_FAILURES.add("hpsf/Test0313rur.adm"); EXPECTED_EXTRACTOR_FAILURES.add("hpsf/Test0313rur.adm");
EXPECTED_EXTRACTOR_FAILURES.add("hsmf/attachment_msg_pdf.msg");
EXPECTED_EXTRACTOR_FAILURES.add("poifs/Notes.ole2"); EXPECTED_EXTRACTOR_FAILURES.add("poifs/Notes.ole2");
EXPECTED_EXTRACTOR_FAILURES.add("slideshow/testPPT.thmx");
} }
public void handleExtracting(File file) throws Exception { public void handleExtracting(File file) throws Exception {
@ -94,7 +90,7 @@ public abstract class AbstractFileHandler implements FileHandler {
assertNotNull(metadataExtractor.getText()); assertNotNull(metadataExtractor.getText());
assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!", assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
EXPECTED_EXTRACTOR_FAILURES.contains(file)); EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
assertEquals("File should not be modified by extractor", length, file.length()); assertEquals("File should not be modified by extractor", length, file.length());
assertEquals("File should not be modified by extractor", modified, file.lastModified()); assertEquals("File should not be modified by extractor", modified, file.lastModified());
@ -114,7 +110,7 @@ public abstract class AbstractFileHandler implements FileHandler {
} }
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
if(!EXPECTED_EXTRACTOR_FAILURES.contains(file)) { if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
throw e; throw e;
} }
} finally { } finally {
@ -122,9 +118,7 @@ public abstract class AbstractFileHandler implements FileHandler {
} }
} }
private void handleExtractingAsStream(File file) throws FileNotFoundException, private void handleExtractingAsStream(File file) throws IOException, OpenXML4JException, XmlException {
IOException, InvalidFormatException, OpenXML4JException,
XmlException {
InputStream stream = new FileInputStream(file); InputStream stream = new FileInputStream(file);
try { try {
POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream); POITextExtractor streamExtractor = ExtractorFactory.createExtractor(stream);

View File

@ -28,7 +28,7 @@ public class HSSFFileHandler extends SpreadsheetHandler {
@Override @Override
public void handleFile(InputStream stream) throws Exception { public void handleFile(InputStream stream) throws Exception {
HSSFWorkbook wb = new HSSFWorkbook(stream); HSSFWorkbook wb = new HSSFWorkbook(stream);
handleWorkbook(wb, ".xls"); handleWorkbook(wb);
// TODO: some documents fail currently... // TODO: some documents fail currently...
//HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); //HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);

View File

@ -20,7 +20,6 @@ import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@ -32,18 +31,18 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.RecordFormatException;
public abstract class SpreadsheetHandler extends AbstractFileHandler { public abstract class SpreadsheetHandler extends AbstractFileHandler {
public void handleWorkbook(Workbook wb, String extension) throws IOException { public void handleWorkbook(Workbook wb) throws IOException {
// try to access some of the content // try to access some of the content
readContent(wb); readContent(wb);
// write out the file // write out the file
ByteArrayOutputStream out = writeToArray(wb); writeToArray(wb);
// access some more content (we had cases where writing corrupts the data in memory) // access some more content (we had cases where writing corrupts the data in memory)
readContent(wb); readContent(wb);
// write once more // write once more
out = writeToArray(wb); ByteArrayOutputStream out = writeToArray(wb);
// read in the writen file // read in the writen file
Workbook read; Workbook read;
@ -61,8 +60,7 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler {
read.close(); read.close();
} }
private ByteArrayOutputStream writeToArray(Workbook wb) private ByteArrayOutputStream writeToArray(Workbook wb) throws IOException {
throws FileNotFoundException, IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
try { try {
wb.write(stream); wb.write(stream);
@ -88,7 +86,7 @@ public abstract class SpreadsheetHandler extends AbstractFileHandler {
for(Row row : sheet) { for(Row row : sheet) {
for(Cell cell : row) { for(Cell cell : row) {
cell.toString(); assertNotNull(cell.toString());
} }
} }
} }

View File

@ -30,7 +30,6 @@ import java.util.Iterator;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
@ -55,7 +54,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
wb = new XSSFWorkbook(new ByteArrayInputStream(bytes)); wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
// use the combined handler for HSSF/XSSF // use the combined handler for HSSF/XSSF
handleWorkbook(wb, ".xlsx"); handleWorkbook(wb);
// TODO: some documents fail currently... // TODO: some documents fail currently...
//XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb); //XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
@ -73,8 +72,7 @@ public class XSSFFileHandler extends SpreadsheetHandler {
} }
private void checkXSSFReader(OPCPackage p) private void checkXSSFReader(OPCPackage p) throws IOException, OpenXML4JException {
throws IOException, OpenXML4JException, InvalidFormatException {
XSSFReader reader = new XSSFReader(p); XSSFReader reader = new XSSFReader(p);
// these can be null... // these can be null...