Adjust TestExtractorFactory to provide more output to see why it fails on Maven builds on nemo.sonarsource.org

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1575497 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2014-03-08 08:22:03 +00:00
parent 3fe86eca24
commit 382be9f312

View File

@ -20,9 +20,11 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor; import org.apache.poi.POITextExtractor;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hpbf.extractor.PublisherTextExtractor; import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hslf.extractor.PowerPointExtractor;
@ -31,17 +33,14 @@ import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hwpf.extractor.Word6Extractor; import org.apache.poi.hwpf.extractor.Word6Extractor;
import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor; import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor; import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import junit.framework.TestCase;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.opc.OPCPackage;
/** /**
* Test that the extractor factory plays nicely * Test that the extractor factory plays nicely
*/ */
@ -73,49 +72,61 @@ public class TestExtractorFactory extends TestCase {
private File pub; private File pub;
private File getFileAndCheck(POIDataSamples samples, String name) {
File file = samples.getFile(name);
assertNotNull("Did not get a file for " + name, file);
assertTrue("Did not get a type file for " + name, file.isFile());
assertTrue("File did not exist: " + name, file.exists());
return file;
}
@Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance(); POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
xls = ssTests.getFile("SampleSS.xls"); xls = getFileAndCheck(ssTests, "SampleSS.xls");
xlsx = ssTests.getFile("SampleSS.xlsx"); xlsx = getFileAndCheck(ssTests, "SampleSS.xlsx");
xltx = ssTests.getFile("test.xltx"); xltx = getFileAndCheck(ssTests, "test.xltx");
xlsEmb = ssTests.getFile("excel_with_embeded.xls"); xlsEmb = getFileAndCheck(ssTests, "excel_with_embeded.xls");
POIDataSamples wpTests = POIDataSamples.getDocumentInstance(); POIDataSamples wpTests = POIDataSamples.getDocumentInstance();
doc = wpTests.getFile("SampleDoc.doc"); doc = getFileAndCheck(wpTests, "SampleDoc.doc");
doc6 = wpTests.getFile("Word6.doc"); doc6 = getFileAndCheck(wpTests, "Word6.doc");
doc95 = wpTests.getFile("Word95.doc"); doc95 = getFileAndCheck(wpTests, "Word95.doc");
docx = wpTests.getFile("SampleDoc.docx"); docx = getFileAndCheck(wpTests, "SampleDoc.docx");
dotx = wpTests.getFile("test.dotx"); dotx = getFileAndCheck(wpTests, "test.dotx");
docEmb = wpTests.getFile("word_with_embeded.doc"); docEmb = getFileAndCheck(wpTests, "word_with_embeded.doc");
docEmbOOXML = wpTests.getFile("word_with_embeded_ooxml.doc"); docEmbOOXML = getFileAndCheck(wpTests, "word_with_embeded_ooxml.doc");
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
ppt = slTests.getFile("SampleShow.ppt"); ppt = getFileAndCheck(slTests, "SampleShow.ppt");
pptx = slTests.getFile("SampleShow.pptx"); pptx = getFileAndCheck(slTests, "SampleShow.pptx");
txt = slTests.getFile("SampleShow.txt"); txt = getFileAndCheck(slTests, "SampleShow.txt");
POIDataSamples dgTests = POIDataSamples.getDiagramInstance(); POIDataSamples dgTests = POIDataSamples.getDiagramInstance();
vsd = dgTests.getFile("Test_Visio-Some_Random_Text.vsd"); vsd = getFileAndCheck(dgTests, "Test_Visio-Some_Random_Text.vsd");
POIDataSamples pubTests = POIDataSamples.getPublisherInstance(); POIDataSamples pubTests = POIDataSamples.getPublisherInstance();
pub = pubTests.getFile("Simple.pub"); pub = getFileAndCheck(pubTests, "Simple.pub");
POIDataSamples olTests = POIDataSamples.getHSMFInstance(); POIDataSamples olTests = POIDataSamples.getHSMFInstance();
msg = olTests.getFile("quick.msg"); msg = getFileAndCheck(olTests, "quick.msg");
msgEmb = olTests.getFile("attachment_test_msg.msg"); msgEmb = getFileAndCheck(olTests, "attachment_test_msg.msg");
msgEmbMsg = olTests.getFile("attachment_msg_pdf.msg"); msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg");
} }
public void testFile() throws Exception { public void testFile() throws Exception {
// Excel // Excel
assertTrue( POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls);
ExtractorFactory.createExtractor(xls) assertNotNull("Had empty extractor for " + xls, xlsExtractor);
assertTrue("Expected instanceof ExcelExtractor, but had: " + xlsExtractor.getClass(),
xlsExtractor
instanceof ExcelExtractor instanceof ExcelExtractor
); );
assertTrue( assertTrue(
ExtractorFactory.createExtractor(xls).getText().length() > 200 xlsExtractor.getText().length() > 200
); );
assertTrue( assertTrue(
@ -452,27 +463,27 @@ public class TestExtractorFactory extends TestCase {
} }
public void testPreferEventBased() throws Exception { public void testPreferEventBased() throws Exception {
assertEquals(false, ExtractorFactory.getPreferEventExtractor()); assertFalse(ExtractorFactory.getPreferEventExtractor());
assertEquals(false, ExtractorFactory.getThreadPrefersEventExtractors()); assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
ExtractorFactory.setThreadPrefersEventExtractors(true); ExtractorFactory.setThreadPrefersEventExtractors(true);
assertEquals(true, ExtractorFactory.getPreferEventExtractor()); assertTrue(ExtractorFactory.getPreferEventExtractor());
assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
ExtractorFactory.setAllThreadsPreferEventExtractors(false); ExtractorFactory.setAllThreadsPreferEventExtractors(false);
assertEquals(false, ExtractorFactory.getPreferEventExtractor()); assertFalse(ExtractorFactory.getPreferEventExtractor());
assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
assertEquals(Boolean.FALSE, ExtractorFactory.getAllThreadsPreferEventExtractors()); assertEquals(Boolean.FALSE, ExtractorFactory.getAllThreadsPreferEventExtractors());
ExtractorFactory.setAllThreadsPreferEventExtractors(null); ExtractorFactory.setAllThreadsPreferEventExtractors(null);
assertEquals(true, ExtractorFactory.getPreferEventExtractor()); assertTrue(ExtractorFactory.getPreferEventExtractor());
assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
// Check we get the right extractors now // Check we get the right extractors now
@ -495,9 +506,9 @@ public class TestExtractorFactory extends TestCase {
// Put back to normal // Put back to normal
ExtractorFactory.setThreadPrefersEventExtractors(false); ExtractorFactory.setThreadPrefersEventExtractors(false);
assertEquals(false, ExtractorFactory.getPreferEventExtractor()); assertFalse(ExtractorFactory.getPreferEventExtractor());
assertEquals(false, ExtractorFactory.getThreadPrefersEventExtractors()); assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
// And back // And back
assertTrue( assertTrue(