diff --git a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java index cf606c05c..c4e453e58 100644 --- a/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java @@ -19,6 +19,7 @@ package org.apache.poi.stress; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeFalse; import java.io.File; import java.io.FileInputStream; @@ -27,11 +28,13 @@ import java.io.InputStream; import java.util.HashSet; import java.util.Set; +import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POITextExtractor; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; +import org.apache.poi.util.IOUtils; import org.apache.xmlbeans.XmlException; public abstract class AbstractFileHandler implements FileHandler { @@ -75,8 +78,9 @@ public abstract class AbstractFileHandler implements FileHandler { long length = file.length(); long modified = file.lastModified(); - POITextExtractor extractor = ExtractorFactory.createExtractor(file); + POITextExtractor extractor = null; try { + extractor = ExtractorFactory.createExtractor(file); assertNotNull("Should get a POITextExtractor but had none for file " + file, extractor); assertNotNull("Should get some text but had none for file " + file, extractor.getText()); @@ -110,8 +114,12 @@ public abstract class AbstractFileHandler implements FileHandler { if(!EXPECTED_EXTRACTOR_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) { throw e; } + } catch (EncryptedDocumentException e) { + String msg = "org.apache.poi.EncryptedDocumentException: Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files"; + assumeFalse(msg.equals(e.getMessage())); + throw e; } finally { - extractor.close(); + IOUtils.closeQuietly(extractor); } } diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java index 477f8aa64..7ba697f23 100644 --- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -16,8 +16,9 @@ ==================================================================== */ package org.apache.poi.stress; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import java.io.BufferedInputStream; @@ -37,6 +38,7 @@ import java.util.Set; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; +import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIXMLException; import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -75,8 +77,14 @@ public class XSSFFileHandler extends SpreadsheetHandler { POIFSFileSystem poifs = new POIFSFileSystem(bytes); EncryptionInfo ei = new EncryptionInfo(poifs); Decryptor dec = ei.getDecryptor(); - boolean b = dec.verifyPassword(pass); - assertTrue("password mismatch", b); + try { + boolean b = dec.verifyPassword(pass); + assertTrue("password mismatch", b); + } catch (EncryptedDocumentException e) { + String msg = "Export Restrictions in place - please install JCE Unlimited Strength Jurisdiction Policy files"; + assumeFalse(msg.equals(e.getMessage())); + throw e; + } InputStream is = dec.getDataStream(poifs); out.reset(); IOUtils.copy(is, out);