* 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
This commit is contained in:
Dominik Stadler 2014-10-20 14:26:53 +00:00
parent 02a4dc5462
commit 7664c7efa7
5 changed files with 52 additions and 30 deletions

View File

@ -172,10 +172,6 @@ under the License.
<property name="asm.jar" location="${main.lib}/asm-all-5.0.3.jar"/>
<property name="asm.url" value="${repository.m2}/maven2/org/ow2/asm/asm-all/5.0.3/asm-all-5.0.3.jar"/>
<!-- for testing with older Xerces implementation -->
<property name="xerces.jar" location="${main.lib}/xercesImpl-2.6.1.jar"/>
<property name="xerces.url" value="${repository.m2}/maven2/xerces/xercesImpl/2.6.1//xercesImpl-2.6.1.jar"/>
<!-- license checks -->
<property name="rat.jar" location="${main.lib}/apache-rat-0.11.jar"/>
<property name="rat.url" value="${repository.m2}/maven2/org/apache/rat/apache-rat/0.11/apache-rat-0.11.jar"/>
@ -394,6 +390,7 @@ under the License.
<include name="org.jacoco.*-0.6.*"/>
<include name="dom4j*"/>
<include name="apache-rat-0.10*"/>
<include name="xercesImpl-*.jar"/>
</fileset>
</delete>
@ -410,7 +407,6 @@ under the License.
<available file="${asm.jar}"/>
<available file="${jacoco.zip}"/>
<available file="${rat.jar}"/>
<available file="${xerces.jar}"/>
<available file="${dsig.bouncycastle-prov.jar}"/>
<available file="${dsig.bouncycastle-pkix.jar}"/>
<available file="${dsig.xmlsec.jar}"/>
@ -465,10 +461,6 @@ under the License.
<include name="lib/*.jar"/>
</patternset>
</unzip>
<antcall target="downloadfile">
<param name="sourcefile" value="${xerces.url}"/>
<param name="destfile" value="${xerces.jar}"/>
</antcall>
<antcall target="downloadfile">
<param name="sourcefile" value="${rat.url}"/>
<param name="destfile" value="${rat.jar}"/>
@ -1047,6 +1039,7 @@ under the License.
<pathelement path="${ooxml.lite-merged.dir}/ooxml-lite-merged.jar"/>
</classpath>
<classpath refid="test.ooxml.classpath"/>
<classpath refid="ooxml.xmlsec.classpath"/>
<syspropertyset refid="junit.properties"/>
<jvmarg value="${poi.test.locale}"/>
<arg value="-ooxml"/>

View File

@ -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();
}
}
/**

View File

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

View File

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

View File

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