@@ -71,9 +71,14 @@ public class PdfOutlineTest extends ExtendedITextTest {
71
71
public static final String destinationFolder = "./target/test/com/itextpdf/kernel/pdf/PdfOutlineTest/" ;
72
72
73
73
@ BeforeClass
74
- public static void beforeClass () throws FileNotFoundException {
75
- createDestinationFolder (destinationFolder );
76
- PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + "documentWithOutlines.pdf" ));
74
+ public static void before () {
75
+ createOrClearDestinationFolder (destinationFolder );
76
+ }
77
+
78
+ @ Test
79
+ public void createSimpleDocWithOutlines () throws IOException , InterruptedException {
80
+ String filename = "simpleDocWithOutlines.pdf" ;
81
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (destinationFolder + filename ));
77
82
pdfDoc .getCatalog ().setPageMode (PdfName .UseOutlines );
78
83
79
84
PdfPage firstPage = pdfDoc .addNewPage ();
@@ -86,6 +91,8 @@ public static void beforeClass() throws FileNotFoundException {
86
91
secondOutline .addDestination (PdfExplicitDestination .createFit (secondPage ));
87
92
88
93
pdfDoc .close ();
94
+
95
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
89
96
}
90
97
91
98
@ Test
@@ -113,12 +120,11 @@ public void outlinesWithPagesTest() throws IOException {
113
120
}
114
121
}
115
122
116
- @ Before
117
- public void setupAddOutlinesToDocumentTest () throws IOException {
118
- String filename = sourceFolder + "iphone_user_guide.pdf" ;
119
-
120
- PdfReader reader = new PdfReader (filename );
121
- PdfWriter writer = new PdfWriter (destinationFolder + "addOutlinesResult.pdf" );
123
+ @ Test
124
+ public void addOutlinesToDocumentTest () throws IOException , InterruptedException {
125
+ PdfReader reader = new PdfReader (sourceFolder + "iphone_user_guide.pdf" );
126
+ String filename = "addOutlinesToDocumentTest.pdf" ;
127
+ PdfWriter writer = new PdfWriter (destinationFolder + filename );
122
128
PdfDocument pdfDoc = new PdfDocument (reader , writer );
123
129
pdfDoc .setTagged ();
124
130
@@ -135,11 +141,13 @@ public void setupAddOutlinesToDocumentTest() throws IOException {
135
141
outlines .getAllChildren ().get (0 ).getAllChildren ().get (1 ).addOutline ("testOutline" , 1 ).addDestination (PdfExplicitDestination .createFit (pdfDoc .getPage (102 )));
136
142
137
143
pdfDoc .close ();
144
+
145
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
138
146
}
139
147
140
148
@ Test
141
- public void addOutlinesToDocumentTest () throws IOException , InterruptedException {
142
- String filename = destinationFolder + "addOutlinesResult.pdf" ;
149
+ public void readOutlinesFromDocumentTest () throws IOException , InterruptedException {
150
+ String filename = sourceFolder + "addOutlinesResult.pdf" ;
143
151
144
152
PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ));
145
153
PdfOutline outlines = pdfDoc .getOutlines (false );
@@ -151,19 +159,21 @@ public void addOutlinesToDocumentTest() throws IOException, InterruptedException
151
159
}
152
160
}
153
161
154
- @ Before
155
- public void setupRemovePageWithOutlinesTest () throws IOException {
156
- String filename = sourceFolder + "iphone_user_guide.pdf" ;
157
-
158
- PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ), new PdfWriter (destinationFolder + "removePagesWithOutlinesResult.pdf" ));
162
+ @ Test
163
+ @ LogMessages ( messages = @ LogMessage ( messageTemplate = LogMessageConstant . FLUSHED_OBJECT_CONTAINS_REFERENCE_WHICH_NOT_REFER_TO_ANY_OBJECT , count = 36 )) // TODO DEVSIX-1583: destinations are not removed along with page
164
+ public void removePageWithOutlinesTest () throws IOException , InterruptedException {
165
+ String filename = "removePageWithOutlinesTest.pdf" ;
166
+ PdfDocument pdfDoc = new PdfDocument (new PdfReader (sourceFolder + "iphone_user_guide.pdf" ), new PdfWriter (destinationFolder + filename ));
159
167
pdfDoc .removePage (102 );
160
168
161
169
pdfDoc .close ();
170
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
162
171
}
163
172
164
173
@ Test
165
- public void removePageWithOutlinesTest () throws IOException {
166
- String filename = destinationFolder + "removePagesWithOutlinesResult.pdf" ;
174
+ public void readRemovedPageWithOutlinesTest () throws IOException {
175
+ // TODO DEVSIX-1583: src document is taken from the previous removePageWithOutlinesTest test, however it contains numerous destination objects which contain PdfNull instead of page reference
176
+ String filename = sourceFolder + "removePagesWithOutlinesResult.pdf" ;
167
177
168
178
PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ));
169
179
@@ -176,22 +186,24 @@ public void removePageWithOutlinesTest() throws IOException {
176
186
}
177
187
}
178
188
179
- @ Before
180
- public void setupUpdateOutlineTitle () throws IOException {
181
- String filename = sourceFolder + "iphone_user_guide.pdf" ;
182
- PdfReader reader = new PdfReader ( filename ) ;
183
- PdfWriter writer = new PdfWriter (destinationFolder + "updateOutlineTitleResult.pdf" );
189
+ @ Test
190
+ public void updateOutlineTitle () throws IOException , InterruptedException {
191
+ PdfReader reader = new PdfReader ( sourceFolder + "iphone_user_guide.pdf" ) ;
192
+ String filename = "updateOutlineTitle.pdf" ;
193
+ PdfWriter writer = new PdfWriter (destinationFolder + filename );
184
194
PdfDocument pdfDoc = new PdfDocument (reader , writer );
185
195
186
196
PdfOutline outlines = pdfDoc .getOutlines (false );
187
197
outlines .getAllChildren ().get (0 ).getAllChildren ().get (1 ).setTitle ("New Title" );
188
198
189
199
pdfDoc .close ();
200
+
201
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
190
202
}
191
203
192
204
@ Test
193
- public void updateOutlineTitle () throws IOException {
194
- String filename = destinationFolder + "updateOutlineTitleResult.pdf" ;
205
+ public void readOutlineTitle () throws IOException {
206
+ String filename = sourceFolder + "updateOutlineTitleResult.pdf" ;
195
207
PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ));
196
208
197
209
PdfOutline outlines = pdfDoc .getOutlines (false );
@@ -203,12 +215,11 @@ public void updateOutlineTitle() throws IOException {
203
215
}
204
216
}
205
217
206
- @ Before
207
- public void setupAddOutlineInNotOutlineMode () throws IOException {
208
- String filename = sourceFolder + "iphone_user_guide.pdf" ;
209
-
210
- PdfReader reader = new PdfReader (filename );
211
- PdfWriter writer = new PdfWriter (destinationFolder + "addOutlinesWithoutOutlineModeResult.pdf" );
218
+ @ Test
219
+ public void addOutlineInNotOutlineMode () throws IOException , InterruptedException {
220
+ String filename = "addOutlineInNotOutlineMode.pdf" ;
221
+ PdfReader reader = new PdfReader (sourceFolder + "iphone_user_guide.pdf" );
222
+ PdfWriter writer = new PdfWriter (destinationFolder + filename );
212
223
PdfDocument pdfDoc = new PdfDocument (reader , writer );
213
224
214
225
PdfOutline outlines = new PdfOutline (pdfDoc );
@@ -223,11 +234,13 @@ public void setupAddOutlineInNotOutlineMode() throws IOException {
223
234
secondPageChild .addDestination (PdfExplicitDestination .createFit (pdfDoc .getPage (2 )));
224
235
225
236
pdfDoc .close ();
237
+
238
+ Assert .assertNull (new CompareTool ().compareByContent (destinationFolder + filename , sourceFolder + "cmp_" + filename , destinationFolder , "diff_" ));
226
239
}
227
240
228
241
@ Test
229
- public void addOutlineInNotOutlineMode () throws IOException {
230
- String filename = destinationFolder + "addOutlinesWithoutOutlineModeResult.pdf" ;
242
+ public void readOutlineAddedInNotOutlineMode () throws IOException {
243
+ String filename = sourceFolder + "addOutlinesWithoutOutlineModeResult.pdf" ;
231
244
PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ));
232
245
233
246
List <PdfOutline > pageOutlines = pdfDoc .getPage (102 ).getOutlines (true );
@@ -240,7 +253,7 @@ public void addOutlineInNotOutlineMode() throws IOException {
240
253
241
254
@ Test
242
255
public void createDocWithOutlines () throws IOException , InterruptedException {
243
- String filename = destinationFolder + "documentWithOutlines.pdf" ;
256
+ String filename = sourceFolder + "documentWithOutlines.pdf" ;
244
257
245
258
PdfDocument pdfDoc = new PdfDocument (new PdfReader (filename ));
246
259
0 commit comments