[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
This commit is contained in:
PJ Fanning 2022-03-09 20:56:02 +00:00
parent f3e197713b
commit 85356f1d54
2 changed files with 51 additions and 30 deletions

View File

@ -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);
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");
}
}
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");
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
}
}
}

Binary file not shown.