diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-03-09 20:56:02 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-03-09 20:56:02 +0000 |
commit | 85356f1d54346fe3465d6249d0c95e2876640c5f (patch) | |
tree | 0ba52aad2d2c8dec2216693ff8ecc611583af9af /poi-ooxml/src/test | |
parent | f3e197713be76b8214deebd7540b67c944fd21e1 (diff) | |
download | poi-85356f1d54346fe3465d6249d0c95e2876640c5f.tar.gz poi-85356f1d54346fe3465d6249d0c95e2876640c5f.zip |
[bug-65946] remove duplicate Category property from extracted properties
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898805 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/test')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java index 501b61f8a6..7c28d149f7 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java +++ b/poi-ooxml/src/test/java/org/apache/poi/ooxml/TestXMLPropertiesTextExtractor.java @@ -16,11 +16,6 @@ ==================================================================== */ package org.apache.poi.ooxml; -import static org.apache.poi.POITestCase.assertContains; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor; import org.apache.poi.ooxml.util.PackageHelper; @@ -30,6 +25,13 @@ import org.apache.poi.xssf.extractor.XSSFExcelExtractor; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.jupiter.api.Test; +import static org.apache.poi.POITestCase.assertContains; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public final class TestXMLPropertiesTextExtractor { private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); private static final POIDataSamples _slSamples = POIDataSamples.getSlideShowInstance(); @@ -102,43 +104,62 @@ public final class TestXMLPropertiesTextExtractor { @Test void testCustom() throws Exception { - OPCPackage pkg = OPCPackage.open( + OPCPackage pkg = OPCPackage.open( _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm") - ); - XSSFWorkbook wb = new XSSFWorkbook(pkg); + ); + XSSFWorkbook wb = new XSSFWorkbook(pkg); - POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb); - ext.getText(); + POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb); + ext.getText(); - // Now check - String text = ext.getText(); - String cText = ext.getCustomPropertiesText(); + // Now check + String text = ext.getText(); + String cText = ext.getCustomPropertiesText(); - assertContains(text, "description = another value"); - assertContains(cText, "description = another value"); + assertContains(text, "description = another value"); + assertContains(cText, "description = another value"); - ext.close(); + ext.close(); } /** * Bug #49386 - some properties, especially - * dates can be null + * dates can be null */ @Test void testWithSomeNulls() throws Exception { - OPCPackage pkg = OPCPackage.open( - _slSamples.openResourceAsStream("49386-null_dates.pptx") - ); - XSLFSlideShow sl = new XSLFSlideShow(pkg); - - POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(sl); - ext.getText(); - - String text = ext.getText(); - assertFalse(text.contains("Created =")); // With date is null - assertContains(text, "CreatedString = "); // Via string is blank - assertContains(text, "LastModifiedBy = IT Client Services"); + try ( + OPCPackage pkg = OPCPackage.open( + _slSamples.openResourceAsStream("49386-null_dates.pptx") + ); + XSLFSlideShow sl = new XSLFSlideShow(pkg); + POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(sl) + ) { + String text = ext.getText(); + assertFalse(text.contains("Created =")); // With date is null + assertContains(text, "CreatedString = "); // Via string is blank + assertContains(text, "LastModifiedBy = IT Client Services"); + } + } - ext.close(); + /** + * Bug #65946 - a bug led to Category being added twice + */ + @Test + void testCategoryProperty() throws Exception { + try ( + OPCPackage pkg = OPCPackage.open( + _slSamples.openResourceAsStream("rain.pptx") + ); + XSLFSlideShow sl = new XSLFSlideShow(pkg); + POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(sl) + ) { + String text = ext.getText(); + int idx0 = text.indexOf("Category ="); + assertNotEquals(-1, idx0); + int idx1 = text.indexOf("Category =", idx0 + 1); + assertEquals(-1, idx1); + assertContains(text, "Category = rain"); // Via string is blank + } } } |