Skip to content

Commit 5d48c8a

Browse files
author
Andrei Stryhelski
committed
Replace assertITextFail to assertOnlyITextFail
DEVSIX-9081
1 parent 03652a3 commit 5d48c8a

10 files changed

+48
-76
lines changed

pdfua/src/test/java/com/itextpdf/pdfua/PdfUAAnnotationsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public void screenAnnotationWithMHWithoutAltMediaDataTest(PdfUAConformance pdfUA
748748

749749
if (pdfUAConformance == PdfUAConformance.PDF_UA_1) {
750750
// Verapdf doesn't fail here but it should
751-
framework.assertITextFail("screenAnnotationWithInvalidMHMediaDataTest",
751+
framework.assertOnlyITextFail("screenAnnotationWithInvalidMHMediaDataTest",
752752
PdfUAExceptionMessageConstants.CT_OR_ALT_ENTRY_IS_MISSING_IN_MEDIA_CLIP, pdfUAConformance);
753753
} else if (pdfUAConformance == PdfUAConformance.PDF_UA_2) {
754754
framework.assertBothValid("screenAnnotationWithInvalidMHMediaDataTest", pdfUAConformance);

pdfua/src/test/java/com/itextpdf/pdfua/UaValidationTestFramework.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ public void assertVeraPdfValid(String filename, PdfUAConformance pdfUAConformanc
171171
Assertions.fail("Expected no vera pdf message but was: \n" + veraPdf + "\n");
172172
}
173173

174-
public void assertITextFail(String filename, String expectedMsg, PdfUAConformance pdfUAConformance) {
174+
public void assertOnlyITextFail(String filename, String expectedMsg, PdfUAConformance pdfUAConformance) throws IOException {
175175
checkError(checkErrorLayout("itext_" + filename + getUAConformance(pdfUAConformance) + ".pdf", pdfUAConformance), expectedMsg);
176+
assertVeraPdfValid(filename, pdfUAConformance);
176177
}
177178

178179
private String veraPdfResult(String filename, boolean failureExpected, PdfUAConformance pdfUAConformance)

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUA2AnnotationTypesTest.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ public void markupAnnotationIsNotTaggedTest(PdfName annotType) throws IOExceptio
150150
pdfPage.getPdfObject().put(PdfName.Annots, new PdfArray(annotation));
151151
});
152152
if (PdfName.Redaction.equals(annotType) || PdfName.Projection.equals(annotType)) {
153-
framework.assertITextFail("markupAnnotationIsNotTagged_" + annotType.getValue(),
153+
framework.assertOnlyITextFail("markupAnnotationIsNotTagged_" + annotType.getValue(),
154154
PdfUAExceptionMessageConstants.MARKUP_ANNOT_IS_NOT_TAGGED_AS_ANNOT, PdfUAConformance.PDF_UA_2);
155-
framework.assertVeraPdfValid("markupAnnotationIsNotTagged_" + annotType.getValue(),
156-
PdfUAConformance.PDF_UA_2);
157155
} else {
158156
framework.assertBothFail("markupAnnotationIsNotTagged_" + annotType.getValue(),
159157
PdfUAExceptionMessageConstants.MARKUP_ANNOT_IS_NOT_TAGGED_AS_ANNOT, false,
@@ -180,10 +178,8 @@ public void markupAnnotationIsNotTaggedAsAnnotTest(PdfName annotType) throws IOE
180178
p.setRole(StandardRoles.ARTIFACT);
181179
});
182180
if (PdfName.Redaction.equals(annotType) || PdfName.Projection.equals(annotType)) {
183-
framework.assertITextFail("markupAnnotationIsNotTaggedAsAnnot_" + annotType.getValue(),
181+
framework.assertOnlyITextFail("markupAnnotationIsNotTaggedAsAnnot_" + annotType.getValue(),
184182
PdfUAExceptionMessageConstants.MARKUP_ANNOT_IS_NOT_TAGGED_AS_ANNOT, PdfUAConformance.PDF_UA_2);
185-
framework.assertVeraPdfValid("markupAnnotationIsNotTaggedAsAnnot_" + annotType.getValue(),
186-
PdfUAConformance.PDF_UA_2);
187183
} else {
188184
framework.assertBothFail("markupAnnotationIsNotTaggedAsAnnot_" + annotType.getValue(),
189185
PdfUAExceptionMessageConstants.MARKUP_ANNOT_IS_NOT_TAGGED_AS_ANNOT, false,
@@ -208,10 +204,8 @@ public void markupAnnotationRCAndContentsTest(PdfName annotType) throws IOExcept
208204
pdfPage.addAnnotation(annotation);
209205
});
210206
if (PdfName.Redaction.equals(annotType) || PdfName.Projection.equals(annotType)) {
211-
framework.assertITextFail("markupAnnotationRCAndContents_" + annotType.getValue(),
207+
framework.assertOnlyITextFail("markupAnnotationRCAndContents_" + annotType.getValue(),
212208
PdfUAExceptionMessageConstants.RC_DIFFERENT_FROM_CONTENTS, PdfUAConformance.PDF_UA_2);
213-
framework.assertVeraPdfValid("markupAnnotationRCAndContents_" + annotType.getValue(),
214-
PdfUAConformance.PDF_UA_2);
215209
} else {
216210
framework.assertBothFail("markupAnnotationRCAndContents_" + annotType.getValue(),
217211
PdfUAExceptionMessageConstants.RC_DIFFERENT_FROM_CONTENTS, false,
@@ -279,9 +273,8 @@ public void annotationEmptyContentsTest(PdfName annotType) throws IOException {
279273
annotation.setContents("");
280274
pdfPage.addAnnotation(annotation);
281275
});
282-
framework.assertITextFail("annotationEmptyContents_" + annotType.getValue(),
276+
framework.assertOnlyITextFail("annotationEmptyContents_" + annotType.getValue(),
283277
PdfUAExceptionMessageConstants.ANNOT_CONTENTS_IS_NULL_OR_EMPTY, PdfUAConformance.PDF_UA_2);
284-
framework.assertVeraPdfValid("annotationEmptyContents_" + annotType.getValue(), PdfUAConformance.PDF_UA_2);
285278
}
286279

287280
@Test
@@ -447,9 +440,8 @@ public void watermarkAnnotationAsRealContentTest() throws IOException {
447440
annot.put(PdfName.RC, new PdfString("<p>Rich text</p>"));
448441
pdfPage.addAnnotation(annot);
449442
});
450-
framework.assertITextFail("watermarkAnnotationAsRealContent",
443+
framework.assertOnlyITextFail("watermarkAnnotationAsRealContent",
451444
PdfUAExceptionMessageConstants.RC_DIFFERENT_FROM_CONTENTS, PdfUAConformance.PDF_UA_2);
452-
framework.assertVeraPdfValid("watermarkAnnotationAsRealContent", PdfUAConformance.PDF_UA_2);
453445
}
454446

455447
@Test

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUA2LinkAnnotationTest.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,10 @@ public void sameNamedDestinationsInDifferentStructureElementsOnPageTest(PdfName
229229
PdfNamedDestination namedDestination = getNamedDestination(pdfDoc, structElem, "dest");
230230
addLinkAnnotations(destLocation, pdfDoc, namedDestination);
231231
});
232-
framework.assertITextFail("sameNamedDestinations_" + destLocation.getValue(),
233-
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
234232
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
235233
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
236-
framework.assertVeraPdfValid("sameNamedDestinations_" + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
234+
framework.assertOnlyITextFail("sameNamedDestinations_" + destLocation.getValue(),
235+
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
237236
}
238237

239238
@ParameterizedTest
@@ -244,11 +243,10 @@ public void sameStringDestinationsInDifferentStructureElementsOnPageTest(PdfName
244243
PdfStringDestination namedDestination = getStringDestination(pdfDoc, structElem, "dest");
245244
addLinkAnnotations(destLocation, pdfDoc, namedDestination);
246245
});
247-
framework.assertITextFail("sameStringDestinations_" + destLocation.getValue(),
248-
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
249246
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
250247
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
251-
framework.assertVeraPdfValid("sameStringDestinations_" + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
248+
framework.assertOnlyITextFail("sameStringDestinations_" + destLocation.getValue(),
249+
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
252250
}
253251

254252
@ParameterizedTest
@@ -267,11 +265,11 @@ public void sameStringDestinationsInDifferentStructureElementsSDTest(PdfName des
267265

268266
addLinkAnnotations(destLocation, pdfDoc, namedDestination);
269267
});
270-
framework.assertITextFail("sameStringDestinationsSD_" + destLocation.getValue(),
271-
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
272268
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
273269
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
274-
framework.assertVeraPdfValid("sameStringDestinationsSD_" + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
270+
framework.assertOnlyITextFail("sameStringDestinationsSD_" + destLocation.getValue(),
271+
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
272+
275273
}
276274

277275
@ParameterizedTest
@@ -290,17 +288,15 @@ public void sameStringDestinationsInDifferentStructureElementsDTest(PdfName dest
290288
});
291289
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
292290
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
293-
framework.assertITextFail("sameStringDestinationsD_" + destLocation.getValue(),
294-
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
295291
if (PdfName.SD.equals(destLocation)) {
296-
framework.assertVeraPdfValid("sameStringDestinationsD_" + destLocation.getValue(),
297-
PdfUAConformance.PDF_UA_2);
292+
framework.assertOnlyITextFail("sameStringDestinationsD_" + destLocation.getValue(),
293+
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
298294
} else {
299295
// In case PdfName.D or Dest equals destLocation, VeraPDF doesn't allow actions with structure destination being
300296
// placed in D entry. Instead, it requires structure destination to be added into special SD entry. There is
301297
// no such requirement in released PDF 2.0 spec. Although it is already mentioned in errata version.
302-
framework.assertVeraPdfFail("sameStringDestinationsD_" + destLocation.getValue(),
303-
PdfUAConformance.PDF_UA_2);
298+
framework.assertBothFail("sameStringDestinationsD_" + destLocation.getValue(),
299+
PdfUAExceptionMessageConstants.SAME_LINKS_IN_DIFFERENT_STRUCT_ELEMS, PdfUAConformance.PDF_UA_2);
304300
}
305301
}
306302

@@ -333,12 +329,10 @@ public void differentNamedDestinationsInSameStructureElementTest(PdfName destLoc
333329

334330
addLinkAnnotations(destLocation, pdfDoc, namedDestination1, namedDestination2, false);
335331
});
336-
framework.assertITextFail("differentNamedDestinations_" + destLocation.getValue(),
337-
PdfUAExceptionMessageConstants.DIFFERENT_LINKS_IN_SINGLE_STRUCT_ELEM, PdfUAConformance.PDF_UA_2);
338332
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
339333
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
340-
framework.assertVeraPdfValid("differentNamedDestinations_" + destLocation.getValue(),
341-
PdfUAConformance.PDF_UA_2);
334+
framework.assertOnlyITextFail("differentNamedDestinations_" + destLocation.getValue(),
335+
PdfUAExceptionMessageConstants.DIFFERENT_LINKS_IN_SINGLE_STRUCT_ELEM, PdfUAConformance.PDF_UA_2);
342336
}
343337

344338
@ParameterizedTest
@@ -353,12 +347,10 @@ public void differentStringDestinationsInSameStructureElementTest(PdfName destLo
353347

354348
addLinkAnnotations(destLocation, pdfDoc, namedDestination1, namedDestination2, false);
355349
});
356-
framework.assertITextFail("differentStringDestinations_" + destLocation.getValue(),
357-
PdfUAExceptionMessageConstants.DIFFERENT_LINKS_IN_SINGLE_STRUCT_ELEM, PdfUAConformance.PDF_UA_2);
358350
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
359351
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
360-
framework.assertVeraPdfValid("differentStringDestinations_" + destLocation.getValue(),
361-
PdfUAConformance.PDF_UA_2);
352+
framework.assertOnlyITextFail("differentStringDestinations_" + destLocation.getValue(),
353+
PdfUAExceptionMessageConstants.DIFFERENT_LINKS_IN_SINGLE_STRUCT_ELEM, PdfUAConformance.PDF_UA_2);
362354
}
363355

364356
@ParameterizedTest
@@ -465,14 +457,13 @@ private static PdfFont loadFont() {
465457
private void validate(String filename, String expectedMessage, PdfName destLocation) throws IOException {
466458
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
467459
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
468-
framework.assertITextFail(filename + destLocation.getValue(), expectedMessage, PdfUAConformance.PDF_UA_2);
469460
if (PdfName.D.equals(destLocation)) {
470461
// In case PdfName.D equals destLocation, VeraPDF doesn't allow actions with structure destination being
471462
// placed in D entry. Instead, it requires structure destination to be added into special SD entry. There is
472463
// no such requirement in released PDF 2.0 spec. Although it is already mentioned in errata version.
473-
framework.assertVeraPdfFail(filename + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
464+
framework.assertBothFail(filename + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
474465
} else {
475-
framework.assertVeraPdfValid(filename + destLocation.getValue(), PdfUAConformance.PDF_UA_2);
466+
framework.assertOnlyITextFail(filename + destLocation.getValue(), expectedMessage, PdfUAConformance.PDF_UA_2);
476467
}
477468
}
478469
}

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUADestinationsTest.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ public void pureExplicitDestinationTest(String destinationWrapType) throws IOExc
123123
framework.assertBothValid(filename, PdfUAConformance.PDF_UA_2);
124124
break;
125125
case "GoToInRandomPlace":
126-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
127126
// iText fails because of the way we search for goto actions.
128127
// We traverse whole document looking for a dictionary, which can represent GoTo action.
129128
// That's why in this particular example we fail, however in reality GoTo action cannot be added directly to catalog.
130-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
129+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
131130
break;
132131
}
133132
}
@@ -202,11 +201,10 @@ public void namedDestinationWithExplicitDestinationTest(String destinationWrapTy
202201
framework.assertBothValid(filename, PdfUAConformance.PDF_UA_2);
203202
break;
204203
case "GoToInRandomPlace":
205-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
206204
// iText fails because of the way we search for goto actions.
207205
// We traverse whole document looking for a dictionary, which can represent GoTo action.
208206
// That's why in this particular example we fail, however in reality GoTo action cannot be added directly to catalog.
209-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
207+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
210208
break;
211209
}
212210
}
@@ -231,8 +229,7 @@ public void namedDestinationWithDictionaryAndSDWithExplicitDestinationTest(Strin
231229
// SD is specifically reserved for structure destinations,
232230
// that's why placing not structure destination in there is wrong in the first place.
233231
// However, if one is placed there, UA-2 exception is expected.
234-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
235-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION,
232+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION,
236233
PdfUAConformance.PDF_UA_2);
237234
break;
238235
case "GoToR":
@@ -288,11 +285,10 @@ public void namedDestinationWithCyclicReferenceTest(String destinationWrapType)
288285
framework.assertBothValid(filename, PdfUAConformance.PDF_UA_2);
289286
break;
290287
case "GoToInRandomPlace":
291-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
292288
// iText fails because of the way we search for goto actions.
293289
// We traverse whole document looking for a dictionary, which can represent GoTo action.
294290
// That's why in this particular example we fail, however in reality GoTo action cannot be added directly to catalog.
295-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
291+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
296292
break;
297293
}
298294
}
@@ -367,11 +363,10 @@ public void stringDestinationWithExplicitDestinationTest(String destinationWrapT
367363
framework.assertBothValid(filename, PdfUAConformance.PDF_UA_2);
368364
break;
369365
case "GoToInRandomPlace":
370-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
371366
// iText fails because of the way we search for goto actions.
372367
// We traverse whole document looking for a dictionary, which can represent GoTo action.
373368
// That's why in this particular example we fail, however in reality GoTo action cannot be added directly to catalog.
374-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
369+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION, PdfUAConformance.PDF_UA_2);
375370
break;
376371
}
377372
}
@@ -396,8 +391,7 @@ public void stringDestinationWithDictionaryAndSDWithExplicitDestinationTest(Stri
396391
// SD is specifically reserved for structure destinations,
397392
// that's why placing not structure destination in there is wrong in the first place.
398393
// However, if one is placed there, UA-2 exception is expected.
399-
framework.assertVeraPdfValid(filename, PdfUAConformance.PDF_UA_2);
400-
framework.assertITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION,
394+
framework.assertOnlyITextFail(filename, PdfUAExceptionMessageConstants.DESTINATION_NOT_STRUCTURE_DESTINATION,
401395
PdfUAConformance.PDF_UA_2);
402396
break;
403397
case "GoToR":

pdfua/src/test/java/com/itextpdf/pdfua/checkers/PdfUAFormFieldsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,11 +2362,10 @@ public void widgetNeitherFormNorArtifactTest(PdfUAConformance pdfUAConformance)
23622362
framework.assertBothFail("widgetNeitherFormNorArtifact",
23632363
PdfUAExceptionMessageConstants.WIDGET_SHALL_BE_FORM_OR_ARTIFACT, pdfUAConformance);
23642364
} else if (PdfUAConformance.PDF_UA_2 == pdfUAConformance) {
2365-
framework.assertITextFail("widgetNeitherFormNorArtifact",
2366-
PdfUAExceptionMessageConstants.WIDGET_SHALL_BE_FORM_OR_ARTIFACT, pdfUAConformance);
23672365
// TODO DEVSIX-9036. VeraPDF claims the document to be valid, although it's not.
23682366
// We will need to update this test when veraPDF behavior is fixed and veraPDF version is updated.
2369-
framework.assertVeraPdfValid("widgetNeitherFormNorArtifact", pdfUAConformance);
2367+
framework.assertOnlyITextFail("widgetNeitherFormNorArtifact",
2368+
PdfUAExceptionMessageConstants.WIDGET_SHALL_BE_FORM_OR_ARTIFACT, pdfUAConformance);
23702369
}
23712370
}
23722371

0 commit comments

Comments
 (0)