From commits-return-14183-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Tue Feb 5 20:05:30 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A06BE180608 for ; Tue, 5 Feb 2019 21:05:29 +0100 (CET) Received: (qmail 61358 invoked by uid 500); 5 Feb 2019 20:05:28 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 61344 invoked by uid 99); 5 Feb 2019 20:05:28 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2019 20:05:28 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id F068B3A01C3 for ; Tue, 5 Feb 2019 20:05:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1853034 - in /pdfbox/branches/2.0/pdfbox: ./ src/test/java/org/apache/pdfbox/multipdf/ src/test/java/org/apache/pdfbox/pdmodel/interactive/form/ Date: Tue, 05 Feb 2019 20:05:27 -0000 To: commits@pdfbox.apache.org From: tallison@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190205200527.F068B3A01C3@svn01-us-west.apache.org> Author: tallison Date: Tue Feb 5 20:05:27 2019 New Revision: 1853034 URL: http://svn.apache.org/viewvc?rev=1853034&view=rev Log: PDFBOX-4388 -- convert unit tests relying on URL#openStream() to wget Modified: pdfbox/branches/2.0/pdfbox/pom.xml pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java Modified: pdfbox/branches/2.0/pdfbox/pom.xml URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/pom.xml?rev=1853034&r1=1853033&r2=1853034&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/pom.xml (original) +++ pdfbox/branches/2.0/pdfbox/pom.xml Tue Feb 5 20:05:27 2019 @@ -186,6 +186,84 @@ download-maven-plugin + PDFBOX-1031-1 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12481683/1.pdf + ${project.build.directory}/pdfs + PDFBOX-1031-1.pdf + f943df43cc2a6929caa484c79eafa44b06a5902e325139e19e1f1ebda7c5fd0c86cc221311659d68351c0ff56d921350ff61e97b9d2c425180d810842c963a5b + + + + PDFBOX-1031-2 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12481684/2.pdf + ${project.build.directory}/pdfs + PDFBOX-1031-2.pdf + 8a9e836ad77c3e9e1e75476f4b46ff4b8958c099970bf57a0b4789fd37236b2bed7e1f14909fa0e3bbacf1a867c1a5c56cbe293383275c1b9c6c0396bec51085 + + + + PDFBOX-1065-1 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12486525/1_testfile1.pdf + ${project.build.directory}/pdfs + PDFBOX-1065-1.pdf + 6b44f363653a9c0cba049495d0ed67659f98b2622b25d647ae556dc4a708847f6c3e4428aa5de2fa0d67f5e8ba08183abf9e8e640e474c6b00c544782e3bba3e + + + + PDFBOX-1065-2 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12486526/2_testfile1.pdf + ${project.build.directory}/pdfs + PDFBOX-1065-2.pdf + 3b19a2a4c35fbacb36774553bedc0b3f2caf60d96aa021a9151d1f18a248577f13229f101ed7ed4375f36b9f481c0488ceb5ac00e4669d6802cd7cee1b0b4ad7 + + + + PDFBOX-1100-1 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12490774/a.pdf + ${project.build.directory}/pdfs + PDFBOX-1100-1.pdf + 9e59c8eb5cde5823a78e8e773bab393ab52eb5ac3f3a576b5d665d0267dca9c677abe08bb3b503a8ebf43479b4e6f61725ad85affd95803e12009c0b1919111a + + + + PDFBOX-1100-2 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12490775/b.pdf + ${project.build.directory}/pdfs + PDFBOX-1100-2.pdf + f55ec23a9b7350410eef95e6bd6de3c3605fa3dc2e9f9c28dfd2f6007bd693da252787350ad6d1d49570ee07fbbfcaba1f8638c1d7e63d4a8875f44c39867e6f + + + PDFBOX-3208 generate-test-resources @@ -198,6 +276,32 @@ + PDFBOX-3656 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12848122/SF1199AEG%20%28Complete%29.pdf + ${project.build.directory}/pdfs + PDFBOX-3656.pdf + 031d958a84cbd9eb520e5af308f635b37c48b77f7df4e43ecbcdabd04f4ba8574fac71b62548594b0f26e9e4e7fa3c1c7679d66c2a8e4bf141157fb6e50df97d + + + + PDFBOX-3682 + generate-test-resources + + wget + + + https://issues.apache.org/jira/secure/attachment/12852207/test.pdf + ${project.build.directory}/pdfs + PDFBOX-3682.pdf + b57628fc15898c1fbd5947c93659aa40b34071a2e8cf04e46ff787cb01687668456e59a13c3fba8b56ab0ef76c933408b3b0f3a781990bfd475cd8fa4325d730 + + + PDFBOX-3940 generate-test-resources Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java?rev=1853034&r1=1853033&r2=1853034&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java (original) +++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAcroFormsTest.java Tue Feb 5 20:05:27 2019 @@ -20,11 +20,13 @@ import static org.junit.Assert.assertEqu import static org.junit.Assert.assertNotNull; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDField; @@ -39,6 +41,7 @@ import org.junit.Test; public class MergeAcroFormsTest { private static final File OUT_DIR = new File("target/test-output/merge/"); + private static final File TARGET_PDF_DIR = new File("target/pdfs"); @Before public void setUp() @@ -51,32 +54,39 @@ public class MergeAcroFormsTest */ @Test public void testAnnotsEntry() throws IOException { - + + InputStream s1 = null; + InputStream s2 = null; // Merge the PDFs form PDFBOX-1031 PDFMergerUtility merger = new PDFMergerUtility(); - - URL url1 = new URL("https://issues.apache.org/jira/secure/attachment/12481683/1.pdf"); - InputStream is1 = url1.openStream(); - - URL url2 = new URL("https://issues.apache.org/jira/secure/attachment/12481684/2.pdf"); - InputStream is2 = url2.openStream(); - File pdfOutput = new File(OUT_DIR,"PDFBOX-1031.pdf"); - merger.setDestinationFileName(pdfOutput.getAbsolutePath()); - merger.addSource(is1); - merger.addSource(is2); - merger.mergeDocuments(null); - - // Test merge result - PDDocument mergedPDF = PDDocument.load(pdfOutput); - assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); - - assertNotNull("There shall be an /Annots entry for the first page", mergedPDF.getPage(0).getCOSObject().getDictionaryObject(COSName.ANNOTS)); - assertEquals("There shall be 1 annotation for the first page", 1, mergedPDF.getPage(0).getAnnotations().size()); - - assertNotNull("There shall be an /Annots entry for the second page", mergedPDF.getPage(1).getCOSObject().getDictionaryObject(COSName.ANNOTS)); - assertEquals("There shall be 1 annotation for the second page", 1, mergedPDF.getPage(0).getAnnotations().size()); - - mergedPDF.close(); + try { + File f1 = new File(TARGET_PDF_DIR, "PDFBOX-1031-1.pdf"); + s1 = new FileInputStream(f1); + + File f2 = new File(TARGET_PDF_DIR, "PDFBOX-1031-2.pdf"); + s2 = new FileInputStream(f2); + + File pdfOutput = new File(OUT_DIR, "PDFBOX-1031.pdf"); + merger.setDestinationFileName(pdfOutput.getAbsolutePath()); + merger.addSource(s1); + merger.addSource(s2); + merger.mergeDocuments(null); + + // Test merge result + PDDocument mergedPDF = PDDocument.load(pdfOutput); + assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); + + assertNotNull("There shall be an /Annots entry for the first page", mergedPDF.getPage(0).getCOSObject().getDictionaryObject(COSName.ANNOTS)); + assertEquals("There shall be 1 annotation for the first page", 1, mergedPDF.getPage(0).getAnnotations().size()); + + assertNotNull("There shall be an /Annots entry for the second page", mergedPDF.getPage(1).getCOSObject().getDictionaryObject(COSName.ANNOTS)); + assertEquals("There shall be 1 annotation for the second page", 1, mergedPDF.getPage(0).getAnnotations().size()); + + mergedPDF.close(); + } finally { + IOUtils.closeQuietly(s1); + IOUtils.closeQuietly(s2); + } } /* @@ -84,35 +94,42 @@ public class MergeAcroFormsTest */ @Test public void testAPEntry() throws IOException { - + + InputStream is1 = null; + InputStream is2 = null; // Merge the PDFs form PDFBOX-1100 PDFMergerUtility merger = new PDFMergerUtility(); - - URL url1 = new URL("https://issues.apache.org/jira/secure/attachment/12490774/a.pdf"); - InputStream is1 = url1.openStream(); - - URL url2 = new URL("https://issues.apache.org/jira/secure/attachment/12490775/b.pdf"); - InputStream is2 = url2.openStream(); - File pdfOutput = new File(OUT_DIR,"PDFBOX-1100.pdf"); - merger.setDestinationFileName(pdfOutput.getAbsolutePath()); - merger.addSource(is1); - merger.addSource(is2); - merger.mergeDocuments(null); - - // Test merge result - PDDocument mergedPDF = PDDocument.load(pdfOutput); - assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); - - PDAcroForm acroForm = mergedPDF.getDocumentCatalog().getAcroForm(); - - PDField formField = acroForm.getField("Testfeld"); - assertNotNull("There shall be an /AP entry for the field", formField.getCOSObject().getDictionaryObject(COSName.AP)); - assertNotNull("There shall be a /V entry for the field", formField.getCOSObject().getDictionaryObject(COSName.V)); - - formField = acroForm.getField("Testfeld2"); - assertNotNull("There shall be an /AP entry for the field", formField.getCOSObject().getDictionaryObject(COSName.AP)); - assertNotNull("There shall be a /V entry for the field", formField.getCOSObject().getDictionaryObject(COSName.V)); - mergedPDF.close(); + try { + File file1 = new File(TARGET_PDF_DIR, "PDFBOX-1100-1.pdf"); + is1 = new FileInputStream(file1); + + File file2 = new File(TARGET_PDF_DIR, "PDFBOX-1100-2.pdf"); + is2 = new FileInputStream(file2); + File pdfOutput = new File(OUT_DIR, "PDFBOX-1100.pdf"); + merger.setDestinationFileName(pdfOutput.getAbsolutePath()); + merger.addSource(is1); + merger.addSource(is2); + merger.mergeDocuments(null); + + // Test merge result + PDDocument mergedPDF = PDDocument.load(pdfOutput); + assertEquals("There shall be 2 pages", 2, mergedPDF.getNumberOfPages()); + + PDAcroForm acroForm = mergedPDF.getDocumentCatalog().getAcroForm(); + + PDField formField = acroForm.getField("Testfeld"); + assertNotNull("There shall be an /AP entry for the field", formField.getCOSObject().getDictionaryObject(COSName.AP)); + assertNotNull("There shall be a /V entry for the field", formField.getCOSObject().getDictionaryObject(COSName.V)); + + formField = acroForm.getField("Testfeld2"); + assertNotNull("There shall be an /AP entry for the field", formField.getCOSObject().getDictionaryObject(COSName.AP)); + assertNotNull("There shall be a /V entry for the field", formField.getCOSObject().getDictionaryObject(COSName.V)); + + mergedPDF.close(); + } finally { + IOUtils.closeQuietly(is1); + IOUtils.closeQuietly(is2); + } } } Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java?rev=1853034&r1=1853033&r2=1853034&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java (original) +++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/multipdf/MergeAnnotationsTest.java Tue Feb 5 20:05:27 2019 @@ -20,14 +20,15 @@ import static org.junit.Assert.assertEqu import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentNameDestinationDictionary; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; @@ -40,6 +41,7 @@ import org.junit.Test; public class MergeAnnotationsTest { private static final File OUT_DIR = new File("target/test-output/merge/"); + private static final File TARGET_PDF_DIR = new File("target/pdfs"); @Before public void setUp() @@ -56,45 +58,51 @@ public class MergeAnnotationsTest // Merge the PDFs from PDFBOX-1065 PDFMergerUtility merger = new PDFMergerUtility(); - - URL url1 = new URL("https://issues.apache.org/jira/secure/attachment/12486525/1_testfile1.pdf"); - InputStream is1 = url1.openStream(); + InputStream is1 = null; + InputStream is2 = null; - URL url2 = new URL("https://issues.apache.org/jira/secure/attachment/12486526/2_testfile1.pdf"); - InputStream is2 = url2.openStream(); - File pdfOutput = new File(OUT_DIR,"PDFBOX-1065.pdf"); - merger.setDestinationFileName(pdfOutput.getAbsolutePath()); - merger.addSource(is1); - merger.addSource(is2); - merger.mergeDocuments(null); - - // Test merge result - PDDocument mergedPDF = PDDocument.load(pdfOutput); - assertEquals("There shall be 6 pages", 6, mergedPDF.getNumberOfPages()); - - PDDocumentNameDestinationDictionary destinations = mergedPDF.getDocumentCatalog().getDests(); - - // Each document has 3 annotations with 2 entries in the /Dests dictionary per annotation. One for the - // source and one for the target. - assertEquals("There shall be 12 entries", 12, destinations.getCOSObject().entrySet().size()); - - List sourceAnnotations01 = mergedPDF.getPage(0).getAnnotations(); - List sourceAnnotations02 = mergedPDF.getPage(3).getAnnotations(); - - List targetAnnotations01 = mergedPDF.getPage(2).getAnnotations(); - List targetAnnotations02 = mergedPDF.getPage(5).getAnnotations(); - - // Test for the first set of annotations to be merged an linked correctly - assertEquals("There shall be 3 source annotations at the first page", 3, sourceAnnotations01.size()); - assertEquals("There shall be 3 source annotations at the third page", 3, targetAnnotations01.size()); - assertTrue("The annotations shall match to each other", testAnnotationsMatch(sourceAnnotations01, targetAnnotations01)); - - // Test for the second set of annotations to be merged an linked correctly - assertEquals("There shall be 3 source annotations at the first page", 3, sourceAnnotations02.size()); - assertEquals("There shall be 3 source annotations at the third page", 3, targetAnnotations02.size()); - assertTrue("The annotations shall match to each other", testAnnotationsMatch(sourceAnnotations02, targetAnnotations02)); - - mergedPDF.close(); + try { + File file1 = new File(TARGET_PDF_DIR, "PDFBOX-1065-1.pdf"); + is1 = new FileInputStream(file1); + + File file2 = new File(TARGET_PDF_DIR, "PDFBOX-1065-2.pdf"); + is2 = new FileInputStream(file2); + File pdfOutput = new File(OUT_DIR, "PDFBOX-1065.pdf"); + merger.setDestinationFileName(pdfOutput.getAbsolutePath()); + merger.addSource(is1); + merger.addSource(is2); + merger.mergeDocuments(null); + + // Test merge result + PDDocument mergedPDF = PDDocument.load(pdfOutput); + assertEquals("There shall be 6 pages", 6, mergedPDF.getNumberOfPages()); + + PDDocumentNameDestinationDictionary destinations = mergedPDF.getDocumentCatalog().getDests(); + + // Each document has 3 annotations with 2 entries in the /Dests dictionary per annotation. One for the + // source and one for the target. + assertEquals("There shall be 12 entries", 12, destinations.getCOSObject().entrySet().size()); + + List sourceAnnotations01 = mergedPDF.getPage(0).getAnnotations(); + List sourceAnnotations02 = mergedPDF.getPage(3).getAnnotations(); + + List targetAnnotations01 = mergedPDF.getPage(2).getAnnotations(); + List targetAnnotations02 = mergedPDF.getPage(5).getAnnotations(); + + // Test for the first set of annotations to be merged an linked correctly + assertEquals("There shall be 3 source annotations at the first page", 3, sourceAnnotations01.size()); + assertEquals("There shall be 3 source annotations at the third page", 3, targetAnnotations01.size()); + assertTrue("The annotations shall match to each other", testAnnotationsMatch(sourceAnnotations01, targetAnnotations01)); + + // Test for the second set of annotations to be merged an linked correctly + assertEquals("There shall be 3 source annotations at the first page", 3, sourceAnnotations02.size()); + assertEquals("There shall be 3 source annotations at the third page", 3, targetAnnotations02.size()); + assertTrue("The annotations shall match to each other", testAnnotationsMatch(sourceAnnotations02, targetAnnotations02)); + mergedPDF.close(); + } finally { + IOUtils.closeQuietly(is1); + IOUtils.closeQuietly(is2); + } } /* Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java?rev=1853034&r1=1853033&r2=1853034&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java (original) +++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDButtonTest.java Tue Feb 5 20:05:27 2019 @@ -41,11 +41,11 @@ import org.junit.Test; */ public class PDButtonTest { - - + private static final File IN_DIR = new File("src/test/resources/org/apache/pdfbox/pdmodel/interactive/form"); private static final String NAME_OF_PDF = "AcroFormsBasicFields.pdf"; - + private static final File TARGET_PDF_DIR = new File("target/pdfs"); + private PDDocument document; private PDAcroForm acroForm; @@ -108,15 +108,14 @@ public class PDButtonTest */ public void testRadioButtonWithOptions() { - URL url; + File file; PDDocument pdfDocument = null; try { - url = new URL("https://issues.apache.org/jira/secure/attachment/12848122/SF1199AEG%20%28Complete%29.pdf"); - InputStream is = url.openStream(); + file = new File(TARGET_PDF_DIR, "PDFBOX-3656.pdf"); - pdfDocument = PDDocument.load(is); + pdfDocument = PDDocument.load(file); PDRadioButton radioButton = (PDRadioButton) pdfDocument.getDocumentCatalog().getAcroForm().getField("Checking/Savings"); radioButton.setValue("Off"); @@ -158,15 +157,14 @@ public class PDButtonTest */ public void testOptionsAndNamesNotNumbers() { - URL url; + File file; PDDocument pdfDocument = null; try { - url = new URL("https://issues.apache.org/jira/secure/attachment/12852207/test.pdf"); - InputStream is = url.openStream(); - - pdfDocument = PDDocument.load(is); + file = new File(TARGET_PDF_DIR, "PDFBOX-3682.pdf"); + + pdfDocument = PDDocument.load(file); pdfDocument.getDocumentCatalog().getAcroForm().getField("RadioButton").setValue("c"); PDRadioButton radioButton = (PDRadioButton) pdfDocument.getDocumentCatalog().getAcroForm().getField("RadioButton");