diff options
author | Dominik Stadler <centic@apache.org> | 2018-04-02 17:16:01 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2018-04-02 17:16:01 +0000 |
commit | 2444a5396d73d60042137efe0dc355250ce83da0 (patch) | |
tree | 98241213bd9e3d8ae78400815cf339f4e6b060ce /src/ooxml/testcases | |
parent | ff1120d7ded7e373d3b15aefc3c1823b5812c9e8 (diff) | |
download | poi-2444a5396d73d60042137efe0dc355250ce83da0.tar.gz poi-2444a5396d73d60042137efe0dc355250ce83da0.zip |
Close resources in tests and in case of Exceptions and use try-with-resources. Close the socket-connection during encrpyting/decrypting as soon as it is not needed any more.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1828178 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases')
4 files changed, 21 insertions, 29 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index 345762b371..3670f6fc7a 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -806,6 +806,7 @@ public class TestExtractorFactory { ExtractorFactory.createExtractor(xlsEmb); embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext); assertNotNull(embeds); + ext.close(); // Excel ext = (POIOLE2TextExtractor) diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java b/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java index 249ff01dcb..eb19cecb3e 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/util/TestZipSecureFile.java @@ -33,16 +33,16 @@ public class TestZipSecureFile { // ClassCastException in ZipFile now // The relevant change in the JDK is http://hg.openjdk.java.net/jdk/jdk10/rev/85ea7e83af30#l5.66 - ZipFile thresholdInputStream = new ZipFile(XSSFTestDataSamples.getSampleFile("template.xlsx")); - - ZipSecureFile secureFile = new ZipSecureFile(XSSFTestDataSamples.getSampleFile("template.xlsx")); - - Enumeration<? extends ZipEntry> entries = thresholdInputStream.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - - InputStream inputStream = secureFile.getInputStream(entry); - assertTrue(inputStream.available() > 0); + try (ZipFile thresholdInputStream = new ZipFile(XSSFTestDataSamples.getSampleFile("template.xlsx"))) { + try (ZipSecureFile secureFile = new ZipSecureFile(XSSFTestDataSamples.getSampleFile("template.xlsx"))) { + Enumeration<? extends ZipEntry> entries = thresholdInputStream.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + + InputStream inputStream = secureFile.getInputStream(entry); + assertTrue(inputStream.available() > 0); + } + } } } } diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java index 3db9b4f837..51b863dce9 100644 --- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java +++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java @@ -113,7 +113,7 @@ public class TestSignatureInfo { } @BeforeClass - public static void initBouncy() throws IOException { + public static void initBouncy() { CryptoFunctions.registerBouncyCastle(); // Set cal to now ... only set to fixed date for debugging ... @@ -164,7 +164,7 @@ public class TestSignatureInfo { Calendar cal = LocaleUtil.getLocaleCalendar(LocaleUtil.TIMEZONE_UTC); cal.clear(); cal.setTimeZone(LocaleUtil.TIMEZONE_UTC); - cal.set(2017, 6, 1); + cal.set(2017, Calendar.JULY, 1); SignatureConfig signatureConfig = prepareConfig("test", "CN=Test", pfxInput); signatureConfig.setExecutionTime(cal.getTime()); @@ -440,7 +440,7 @@ public class TestSignatureInfo { if (mockTsp) { TimeStampService tspService = new TimeStampService(){ @Override - public byte[] timeStamp(byte[] data, RevocationData revocationData) throws Exception { + public byte[] timeStamp(byte[] data, RevocationData revocationData) { revocationData.addCRL(crl); return "time-stamp-token".getBytes(LocaleUtil.CHARSET_1252); } @@ -451,14 +451,10 @@ public class TestSignatureInfo { }; signatureConfig.setTspService(tspService); } else { - TimeStampServiceValidator tspValidator = new TimeStampServiceValidator() { - @Override - public void validate(List<X509Certificate> validateChain, - RevocationData revocationData) throws Exception { - for (X509Certificate certificate : validateChain) { - LOG.log(POILogger.DEBUG, "certificate: " + certificate.getSubjectX500Principal()); - LOG.log(POILogger.DEBUG, "validity: " + certificate.getNotBefore() + " - " + certificate.getNotAfter()); - } + TimeStampServiceValidator tspValidator = (validateChain, revocationData) -> { + for (X509Certificate certificate : validateChain) { + LOG.log(POILogger.DEBUG, "certificate: " + certificate.getSubjectX500Principal()); + LOG.log(POILogger.DEBUG, "validity: " + certificate.getNotBefore() + " - " + certificate.getNotAfter()); } }; signatureConfig.setTspValidator(tspValidator); @@ -471,12 +467,7 @@ public class TestSignatureInfo { x509, x509, keyPair.getPrivate(), "SHA1withRSA", cal.getTimeInMillis()); revocationData.addOCSP(ocspResp.getEncoded()); - RevocationDataService revocationDataService = new RevocationDataService(){ - @Override - public RevocationData getRevocationData(List<X509Certificate> revocationChain) { - return revocationData; - } - }; + RevocationDataService revocationDataService = revocationChain -> revocationData; signatureConfig.setRevocationDataService(revocationDataService); // operate diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java index bb9a9a6a45..3958aa2f6e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java @@ -113,8 +113,8 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { writeWorkbook(new XSSFWorkbook(), XSSFITestDataProvider.instance); // does not work - try { - writeWorkbook(new SXSSFWorkbook(), SXSSFITestDataProvider.instance); + try (SXSSFWorkbook wb = new SXSSFWorkbook()) { + writeWorkbook(wb, SXSSFITestDataProvider.instance); fail("Should catch exception here"); } catch (RuntimeException e) { // this is not implemented yet |