From 29ad9ed4a2ab2743c78316c0adccaa532b7cd0a7 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 23 Oct 2014 10:11:42 +0200 Subject: File handle close test --- .../pdfas/cli/test/KeystoreFileHandleClosed.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/KeystoreFileHandleClosed.java (limited to 'pdf-as-cli/src/test') diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/KeystoreFileHandleClosed.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/KeystoreFileHandleClosed.java new file mode 100644 index 00000000..3dc9a269 --- /dev/null +++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/KeystoreFileHandleClosed.java @@ -0,0 +1,44 @@ +package at.gv.egiz.pdfas.cli.test; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.junit.Test; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; + +public class KeystoreFileHandleClosed { + + // -ksf /home/afitzek/devel/pdfas_neu/test.p12 -kst PKCS12 -ksa ecc_test + // -kskp 123456 -kssp 123456 + private static final String origFile = "/home/afitzek/devel/pdfas_neu/test.p12"; + private static final String keyAlias = "ecc_test"; + private static final String keyStorePassword = "123456"; + private static final String keyPassword = "123456"; + private static final String keyStoreType = "PKCS12"; + + @Test + public void test() throws IOException, PdfAsException { + + File origFileFile = new File(origFile); + File tmpKeyStoreFile = new File("/tmp/test.ks"); + FileUtils.copyFile(origFileFile, tmpKeyStoreFile); + try { + PAdESSignerKeystore pAdESSignerKeystore = new PAdESSignerKeystore( + tmpKeyStoreFile.getCanonicalPath(), keyAlias, + keyStorePassword, keyPassword, keyStoreType); + } finally { + if (tmpKeyStoreFile != null && tmpKeyStoreFile.exists()) { + if (!FileUtils.deleteQuietly(tmpKeyStoreFile)) { + fail("Unable to remove temporary keystore file '" + + tmpKeyStoreFile.getAbsolutePath() + "'."); + } + } + } + } + +} -- cgit v1.2.3