From c1bf8e82a93e109943e9a49a68d6865679fabe76 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 20 Oct 2014 14:26:53 +0000 Subject: [PATCH] * Make more tests work in OOXMLLite compilation by adding xml security classpath and ensuring proper cleanup in some Extractor tests * Remove downloading xerces library here, we now do this in the special Jenkins job and thus can get rid of it here git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1633166 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 11 +---- .../TestXSSFEventBasedExcelExtractor.java | 42 ++++++++++++------- ...FEventBasedExcelExtractorUsingFactory.java | 6 +++ .../extractor/TestXSSFExcelExtractor.java | 17 +++++--- .../TestXSSFExcelExtractorUsingFactory.java | 6 +++ 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/build.xml b/build.xml index 5f2aaebd8e..8b83699037 100644 --- a/build.xml +++ b/build.xml @@ -172,10 +172,6 @@ under the License. - - - - @@ -394,6 +390,7 @@ under the License. + @@ -410,7 +407,6 @@ under the License. - @@ -465,10 +461,6 @@ under the License. - - - - @@ -1047,6 +1039,7 @@ under the License. + diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java index 80c1f116b5..e48787be0c 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java @@ -20,13 +20,13 @@ package org.apache.poi.xssf.extractor; import java.util.regex.Matcher; import java.util.regex.Pattern; +import junit.framework.TestCase; + import org.apache.poi.POITextExtractor; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.xssf.XSSFTestDataSamples; -import junit.framework.TestCase; - /** * Tests for {@link XSSFEventBasedExcelExtractor} */ @@ -155,7 +155,8 @@ public class TestXSSFEventBasedExcelExtractor extends TestCase { POITextExtractor[] extractors = new POITextExtractor[] { ooxmlExtractor, ole2Extractor }; for (int i = 0; i < extractors.length; i++) { - POITextExtractor extractor = extractors[i]; + @SuppressWarnings("resource") + POITextExtractor extractor = extractors[i]; String text = extractor.getText().replaceAll("[\r\t]", ""); assertTrue(text.startsWith("First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n")); @@ -175,12 +176,15 @@ public class TestXSSFEventBasedExcelExtractor extends TestCase { public void testShapes() throws Exception{ XSSFEventBasedExcelExtractor ooxmlExtractor = getExtractor("WithTextBox.xlsx"); - String text = ooxmlExtractor.getText(); - - assertTrue(text.indexOf("Line 1") > -1); - assertTrue(text.indexOf("Line 2") > -1); - assertTrue(text.indexOf("Line 3") > -1); - + try { + String text = ooxmlExtractor.getText(); + + assertTrue(text.indexOf("Line 1") > -1); + assertTrue(text.indexOf("Line 2") > -1); + assertTrue(text.indexOf("Line 3") > -1); + } finally { + ooxmlExtractor.close(); + } } /** @@ -229,16 +233,24 @@ public class TestXSSFEventBasedExcelExtractor extends TestCase { XSSFExcelExtractor extractor = new XSSFExcelExtractor( XSSFTestDataSamples.openSampleWorkbook("headerFooterTest.xlsx")); - assertEquals(expectedOutputWithHeadersAndFooters, extractor.getText()); - extractor.setIncludeHeadersFooters(false); - assertEquals(expectedOutputWithoutHeadersAndFooters, extractor.getText()); + try { + assertEquals(expectedOutputWithHeadersAndFooters, extractor.getText()); + extractor.setIncludeHeadersFooters(false); + assertEquals(expectedOutputWithoutHeadersAndFooters, extractor.getText()); + } finally { + extractor.close(); + } XSSFEventBasedExcelExtractor fixture = new XSSFEventBasedExcelExtractor( XSSFTestDataSamples.openSamplePackage("headerFooterTest.xlsx")); - assertEquals(expectedOutputWithHeadersAndFooters, fixture.getText()); - fixture.setIncludeHeadersFooters(false); - assertEquals(expectedOutputWithoutHeadersAndFooters, fixture.getText()); + try { + assertEquals(expectedOutputWithHeadersAndFooters, fixture.getText()); + fixture.setIncludeHeadersFooters(false); + assertEquals(expectedOutputWithoutHeadersAndFooters, fixture.getText()); + } finally { + fixture.close(); + } } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractorUsingFactory.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractorUsingFactory.java index 05e790fd59..34478a909b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractorUsingFactory.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractorUsingFactory.java @@ -26,4 +26,10 @@ public class TestXSSFEventBasedExcelExtractorUsingFactory extends TestXSSFEventB ExtractorFactory.setAllThreadsPreferEventExtractors(true); return (XSSFEventBasedExcelExtractor) ExtractorFactory.createExtractor(HSSFTestDataSamples.openSampleFileStream(sampleName)); } + + @Override + public void tearDown() { + // reset setting to not affect other tests + ExtractorFactory.setAllThreadsPreferEventExtractors(null); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java index b4872d1181..c2b2326c84 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java @@ -134,7 +134,8 @@ public class TestXSSFExcelExtractor extends TestCase { POITextExtractor[] extractors = new POITextExtractor[] { ooxmlExtractor, ole2Extractor }; for (int i = 0; i < extractors.length; i++) { - POITextExtractor extractor = extractors[i]; + @SuppressWarnings("resource") + POITextExtractor extractor = extractors[i]; String text = extractor.getText().replaceAll("[\r\t]", ""); assertTrue(text.startsWith("First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n")); @@ -217,10 +218,14 @@ public class TestXSSFExcelExtractor extends TestCase { */ public void testTextBoxes() throws IOException { XSSFExcelExtractor extractor = getExtractor("WithTextBox.xlsx"); - extractor.setFormulasNotResults(true); - String text = extractor.getText(); - assertTrue(text.indexOf("Line 1") > -1); - assertTrue(text.indexOf("Line 2") > -1); - assertTrue(text.indexOf("Line 3") > -1); + try { + extractor.setFormulasNotResults(true); + String text = extractor.getText(); + assertTrue(text.indexOf("Line 1") > -1); + assertTrue(text.indexOf("Line 2") > -1); + assertTrue(text.indexOf("Line 3") > -1); + } finally { + extractor.close(); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java index fd5cde38e3..57983be005 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractorUsingFactory.java @@ -34,4 +34,10 @@ public final class TestXSSFExcelExtractorUsingFactory extends TestXSSFExcelExtra throw new RuntimeException(e); } } + + @Override + public void tearDown() { + // reset setting to not affect other tests + ExtractorFactory.setAllThreadsPreferEventExtractors(null); + } } -- 2.39.5