diff options
author | Dominik Stadler <centic@apache.org> | 2015-02-27 14:58:41 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2015-02-27 14:58:41 +0000 |
commit | a3e087268a6ff9d5b90d3d334593d56693e400b8 (patch) | |
tree | 8f46d441d3321425accdcf5a5a99f598544957f1 /src/testcases/org/apache/poi/hpsf | |
parent | 27c6da8286197840c0dbe909abb767a25fb5a28e (diff) | |
download | poi-a3e087268a6ff9d5b90d3d334593d56693e400b8.tar.gz poi-a3e087268a6ff9d5b90d3d334593d56693e400b8.zip |
* Verify some more Text-Extraction features as part of integration tests, fix some NullPointerExceptions that showed up now because the event-based extraction does not have a Document available
* Also handle a XLSX which does not have row-numbers in the sheet-xml. Excel can read it so it makes sense to also allow to read it in the XSSFSheetXMLHandler
* Remove some Eclipse warnings in test-code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1662691 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/hpsf')
-rw-r--r-- | src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java | 165 |
1 files changed, 111 insertions, 54 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java index 22238d75f1..c6ad03db2d 100644 --- a/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java +++ b/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java @@ -22,10 +22,12 @@ import java.io.IOException; import junit.framework.TestCase; import org.apache.poi.POIDataSamples; +import org.apache.poi.POITextExtractor; import org.apache.poi.hpsf.Thumbnail; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hwpf.extractor.Word6Extractor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; public final class TestHPSFPropertiesExtractor extends TestCase { @@ -34,45 +36,53 @@ public final class TestHPSFPropertiesExtractor extends TestCase { public void testNormalProperties() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc")); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); - ext.getText(); - - // Check each bit in turn - String sinfText = ext.getSummaryInformationText(); - String dinfText = ext.getDocumentSummaryInformationText(); - - assertTrue(sinfText.indexOf("TEMPLATE = Normal") > -1); - assertTrue(sinfText.indexOf("SUBJECT = sample subject") > -1); - assertTrue(dinfText.indexOf("MANAGER = sample manager") > -1); - assertTrue(dinfText.indexOf("COMPANY = sample company") > -1); - - // Now overall - String text = ext.getText(); - assertTrue(text.indexOf("TEMPLATE = Normal") > -1); - assertTrue(text.indexOf("SUBJECT = sample subject") > -1); - assertTrue(text.indexOf("MANAGER = sample manager") > -1); - assertTrue(text.indexOf("COMPANY = sample company") > -1); + try { + ext.getText(); + + // Check each bit in turn + String sinfText = ext.getSummaryInformationText(); + String dinfText = ext.getDocumentSummaryInformationText(); + + assertTrue(sinfText.indexOf("TEMPLATE = Normal") > -1); + assertTrue(sinfText.indexOf("SUBJECT = sample subject") > -1); + assertTrue(dinfText.indexOf("MANAGER = sample manager") > -1); + assertTrue(dinfText.indexOf("COMPANY = sample company") > -1); + + // Now overall + String text = ext.getText(); + assertTrue(text.indexOf("TEMPLATE = Normal") > -1); + assertTrue(text.indexOf("SUBJECT = sample subject") > -1); + assertTrue(text.indexOf("MANAGER = sample manager") > -1); + assertTrue(text.indexOf("COMPANY = sample company") > -1); + } finally { + ext.close(); + } } public void testNormalUnicodeProperties() throws Exception { POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls")); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); - ext.getText(); - - // Check each bit in turn - String sinfText = ext.getSummaryInformationText(); - String dinfText = ext.getDocumentSummaryInformationText(); - - assertTrue(sinfText.indexOf("AUTHOR = marshall") > -1); - assertTrue(sinfText.indexOf("TITLE = Titel: \u00c4h") > -1); - assertTrue(dinfText.indexOf("COMPANY = Schreiner") > -1); - assertTrue(dinfText.indexOf("SCALE = false") > -1); - - // Now overall - String text = ext.getText(); - assertTrue(text.indexOf("AUTHOR = marshall") > -1); - assertTrue(text.indexOf("TITLE = Titel: \u00c4h") > -1); - assertTrue(text.indexOf("COMPANY = Schreiner") > -1); - assertTrue(text.indexOf("SCALE = false") > -1); + try { + ext.getText(); + + // Check each bit in turn + String sinfText = ext.getSummaryInformationText(); + String dinfText = ext.getDocumentSummaryInformationText(); + + assertTrue(sinfText.indexOf("AUTHOR = marshall") > -1); + assertTrue(sinfText.indexOf("TITLE = Titel: \u00c4h") > -1); + assertTrue(dinfText.indexOf("COMPANY = Schreiner") > -1); + assertTrue(dinfText.indexOf("SCALE = false") > -1); + + // Now overall + String text = ext.getText(); + assertTrue(text.indexOf("AUTHOR = marshall") > -1); + assertTrue(text.indexOf("TITLE = Titel: \u00c4h") > -1); + assertTrue(text.indexOf("COMPANY = Schreiner") > -1); + assertTrue(text.indexOf("SCALE = false") > -1); + } finally { + ext.close(); + } } public void testCustomProperties() throws Exception { @@ -80,18 +90,21 @@ public final class TestHPSFPropertiesExtractor extends TestCase { _samples.openResourceAsStream("TestMickey.doc") ); HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs); - - // Custom properties are part of the document info stream - String dinfText = ext.getDocumentSummaryInformationText(); - assertTrue(dinfText.indexOf("Client = sample client") > -1); - assertTrue(dinfText.indexOf("Division = sample division") > -1); - - String text = ext.getText(); - assertTrue(text.indexOf("Client = sample client") > -1); - assertTrue(text.indexOf("Division = sample division") > -1); + try { + // Custom properties are part of the document info stream + String dinfText = ext.getDocumentSummaryInformationText(); + assertTrue(dinfText.indexOf("Client = sample client") > -1); + assertTrue(dinfText.indexOf("Division = sample division") > -1); + + String text = ext.getText(); + assertTrue(text.indexOf("Client = sample client") > -1); + assertTrue(text.indexOf("Division = sample division") > -1); + } finally { + ext.close(); + } } - public void testConstructors() { + public void testConstructors() throws IOException { POIFSFileSystem fs; HSSFWorkbook wb; try { @@ -102,9 +115,29 @@ public final class TestHPSFPropertiesExtractor extends TestCase { } ExcelExtractor excelExt = new ExcelExtractor(wb); - String fsText = (new HPSFPropertiesExtractor(fs)).getText(); - String hwText = (new HPSFPropertiesExtractor(wb)).getText(); - String eeText = (new HPSFPropertiesExtractor(excelExt)).getText(); + final String fsText; + HPSFPropertiesExtractor fsExt = new HPSFPropertiesExtractor(fs); + try { + fsText = fsExt.getText(); + } finally { + fsExt.close(); + } + + final String hwText; + HPSFPropertiesExtractor hwExt = new HPSFPropertiesExtractor(wb); + try { + hwText = hwExt.getText(); + } finally { + hwExt.close(); + } + + final String eeText; + HPSFPropertiesExtractor eeExt = new HPSFPropertiesExtractor(excelExt); + try { + eeText = eeExt.getText(); + } finally { + eeExt.close(); + } assertEquals(fsText, hwText); assertEquals(fsText, eeText); @@ -113,13 +146,17 @@ public final class TestHPSFPropertiesExtractor extends TestCase { assertTrue(fsText.indexOf("TITLE = Titel: \u00c4h") > -1); } - public void test42726() { - HPSFPropertiesExtractor ex = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls")); - String txt = ex.getText(); - assertTrue(txt.indexOf("PID_AUTHOR") != -1); - assertTrue(txt.indexOf("PID_EDITTIME") != -1); - assertTrue(txt.indexOf("PID_REVNUMBER") != -1); - assertTrue(txt.indexOf("PID_THUMBNAIL") != -1); + public void test42726() throws IOException { + HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(HSSFTestDataSamples.openSampleWorkbook("42726.xls")); + try { + String txt = ext.getText(); + assertTrue(txt.indexOf("PID_AUTHOR") != -1); + assertTrue(txt.indexOf("PID_EDITTIME") != -1); + assertTrue(txt.indexOf("PID_REVNUMBER") != -1); + assertTrue(txt.indexOf("PID_THUMBNAIL") != -1); + } finally { + ext.close(); + } } public void testThumbnail() throws Exception { @@ -131,4 +168,24 @@ public final class TestHPSFPropertiesExtractor extends TestCase { assertNotNull(thumbnail.getThumbnailAsWMF()); wb.close(); } + + public void testExtractorFromWord6Extractor() throws Exception { + POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc")); + Word6Extractor wExt = new Word6Extractor(fs); + try { + POITextExtractor ext = wExt.getMetadataTextExtractor(); + try { + // Now overall + String text = ext.getText(); + assertTrue(text.indexOf("TEMPLATE = Normal") > -1); + assertTrue(text.indexOf("SUBJECT = sample subject") > -1); + assertTrue(text.indexOf("MANAGER = sample manager") > -1); + assertTrue(text.indexOf("COMPANY = sample company") > -1); + } finally { + ext.close(); + } + } finally { + wExt.close(); + } + } } |