Skip to content

Commit 6d3b595

Browse files
Kate IvanovaUbuntu
authored andcommitted
Add tests on copying page with widget annotations GoTo actions
DEVSIX-6356
1 parent df1b913 commit 6d3b595

7 files changed

+69
-16
lines changed

kernel/src/test/java/com/itextpdf/kernel/pdf/copy/PdfAnnotationCopyingTest.java

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.kernel.pdf.copy;
2424

2525
import com.itextpdf.commons.utils.MessageFormatUtil;
26+
import com.itextpdf.io.logs.IoLogMessageConstant;
2627
import com.itextpdf.kernel.geom.Rectangle;
2728
import com.itextpdf.kernel.pdf.PdfArray;
2829
import com.itextpdf.kernel.pdf.PdfDictionary;
@@ -39,6 +40,8 @@ This file is part of the iText (R) project.
3940
import com.itextpdf.kernel.pdf.navigation.PdfExplicitDestination;
4041
import com.itextpdf.kernel.utils.CompareTool;
4142
import com.itextpdf.test.ExtendedITextTest;
43+
import com.itextpdf.test.annotations.LogMessage;
44+
import com.itextpdf.test.annotations.LogMessages;
4245
import com.itextpdf.test.annotations.type.IntegrationTest;
4346

4447
import java.io.ByteArrayInputStream;
@@ -53,19 +56,19 @@ This file is part of the iText (R) project.
5356
@Category(IntegrationTest.class)
5457
public class PdfAnnotationCopyingTest extends ExtendedITextTest {
5558

56-
public static final String destinationFolder = "./target/test/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/";
57-
public static final String sourceFolder = "./src/test/resources/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/";
59+
public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/";
60+
public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/kernel/pdf/PdfAnnotationCopyingTest/";
5861

5962
@BeforeClass
6063
public static void beforeClass() {
61-
createOrClearDestinationFolder(destinationFolder);
64+
createOrClearDestinationFolder(DESTINATION_FOLDER);
6265
}
6366

6467
@Test
6568
@Ignore("Unignore when DEVSIX-3585 would be implemented")
6669
public void testCopyingPageWithAnnotationContainingPopupKey() throws IOException {
67-
String inFilePath = sourceFolder + "annotation-with-popup.pdf";
68-
String outFilePath = destinationFolder + "copy-annotation-with-popup.pdf";
70+
String inFilePath = SOURCE_FOLDER + "annotation-with-popup.pdf";
71+
String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-popup.pdf";
6972
PdfDocument originalDocument = new PdfDocument(new PdfReader(inFilePath));
7073
PdfDocument outDocument = new PdfDocument(new PdfWriter(outFilePath));
7174

@@ -108,8 +111,8 @@ public void testCopyingPageWithAnnotationContainingPopupKey() throws IOException
108111
@Test
109112
@Ignore("Unignore when DEVSIX-3585 would be implemented")
110113
public void testCopyingPageWithAnnotationContainingIrtKey() throws IOException {
111-
String inFilePath = sourceFolder + "annotation-with-irt.pdf";
112-
String outFilePath = destinationFolder + "copy-annotation-with-irt.pdf";
114+
String inFilePath = SOURCE_FOLDER + "annotation-with-irt.pdf";
115+
String outFilePath = DESTINATION_FOLDER + "copy-annotation-with-irt.pdf";
113116
PdfDocument originalDocument = new PdfDocument(new PdfReader(inFilePath));
114117
PdfDocument outDocument = new PdfDocument(new PdfWriter(outFilePath));
115118

@@ -148,34 +151,68 @@ public void testCopyingPageWithAnnotationContainingIrtKey() throws IOException {
148151
@Test
149152
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
150153
public void copySameLinksWithGoToSmartModeTest() throws IOException, InterruptedException {
151-
String cmpFilePath = sourceFolder + "cmp_copySameLinksWithGoToSmartMode.pdf";
152-
String outFilePath = destinationFolder + "copySameLinksWithGoToSmartMode.pdf";
154+
String cmpFilePath = SOURCE_FOLDER + "cmp_copySameLinksWithGoToSmartMode.pdf";
155+
String outFilePath = DESTINATION_FOLDER + "copySameLinksWithGoToSmartMode.pdf";
153156

154157
copyLinksGoToActionTest(outFilePath, true, false);
155158

156-
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, destinationFolder));
159+
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER));
157160
}
158161

159162
@Test
160163
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
161164
public void copyDiffDestLinksWithGoToSmartModeTest() throws IOException, InterruptedException {
162-
String cmpFilePath = sourceFolder + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf";
163-
String outFilePath = destinationFolder + "copyDiffDestLinksWithGoToSmartMode.pdf";
165+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDestLinksWithGoToSmartMode.pdf";
166+
String outFilePath = DESTINATION_FOLDER + "copyDiffDestLinksWithGoToSmartMode.pdf";
164167

165168
copyLinksGoToActionTest(outFilePath, false, false);
166169

167-
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, destinationFolder));
170+
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER));
168171
}
169172

170173
@Test
171174
// TODO DEVSIX-4238 Update cmp file after the ticket DEVSIX-4238 will be resolved
172175
public void copyDiffDisplayLinksWithGoToSmartModeTest() throws IOException, InterruptedException {
173-
String cmpFilePath = sourceFolder + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf";
174-
String outFilePath = destinationFolder + "copyDiffDisplayLinksWithGoToSmartMode.pdf";
176+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyDiffDisplayLinksWithGoToSmartMode.pdf";
177+
String outFilePath = DESTINATION_FOLDER + "copyDiffDisplayLinksWithGoToSmartMode.pdf";
175178

176179
copyLinksGoToActionTest(outFilePath, false, true);
177180

178-
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, destinationFolder));
181+
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER));
182+
}
183+
184+
@Test
185+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
186+
@LogMessages(messages = {
187+
@LogMessage(messageTemplate = IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)})
188+
public void copyPagesWithWidgetAnnotGoToActionExplicitDestTest() throws IOException, InterruptedException {
189+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionExplicitDest.pdf";
190+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf";
191+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionExplicitDest.pdf";
192+
193+
copyPages(srcFilePath, outFilePath, cmpFilePath);
194+
}
195+
196+
@Test
197+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
198+
@LogMessages(messages = {
199+
@LogMessage(messageTemplate = IoLogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY)})
200+
public void copyPagesWithWidgetAnnotGoToActionNamedDestTest() throws IOException, InterruptedException {
201+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithWidgetAnnotGoToActionNamedDest.pdf";
202+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithWidgetAnnotGoToActionNamedDest.pdf";
203+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithWidgetAnnotGoToActionNamedDest.pdf";
204+
205+
copyPages(srcFilePath, outFilePath, cmpFilePath);
206+
}
207+
208+
@Test
209+
// TODO: DEVSIX-6090 (update cmp file after fixing the issue)
210+
public void copyPagesWithScreenAnnotGoToActionExplicitDestTest() throws IOException, InterruptedException {
211+
String srcFilePath = SOURCE_FOLDER + "pageToCopyWithScreenAnnotGoToActionExplicitDest.pdf";
212+
String cmpFilePath = SOURCE_FOLDER + "cmp_copyPagesWithScreenAnnotGoToActionExplicitDest.pdf";
213+
String outFilePath = DESTINATION_FOLDER + "copyPagesWithScreenAnnotGoToActionExplicitDest.pdf";
214+
215+
copyPages(srcFilePath, outFilePath, cmpFilePath);
179216
}
180217

181218
private void copyLinksGoToActionTest(String dest, boolean isTheSameLinks, boolean diffDisplayOptions)
@@ -190,6 +227,22 @@ private void copyLinksGoToActionTest(String dest, boolean isTheSameLinks, boolea
190227
destDoc.close();
191228
}
192229

230+
private void copyPages(String sourceFile, String outFilePath, String cmpFilePath)
231+
throws IOException, InterruptedException {
232+
try (PdfWriter writer = new PdfWriter(outFilePath);
233+
PdfDocument pdfDoc = new PdfDocument(writer)) {
234+
pdfDoc.addNewPage();
235+
pdfDoc.addNewPage();
236+
237+
try (PdfReader reader = new PdfReader(sourceFile);
238+
PdfDocument srcDoc = new PdfDocument(reader)) {
239+
srcDoc.copyPagesTo(1, srcDoc.getNumberOfPages(), pdfDoc);
240+
}
241+
}
242+
243+
Assert.assertNull(new CompareTool().compareByContent(outFilePath, cmpFilePath, DESTINATION_FOLDER));
244+
}
245+
193246
private ByteArrayOutputStream createPdfWithGoToAnnot(boolean isTheSameLink, boolean diffDisplayOptions) {
194247
ByteArrayOutputStream stream = new ByteArrayOutputStream();
195248
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(stream));

0 commit comments

Comments
 (0)