Skip to content

Commit 0fdc3a0

Browse files
author
Andrei Stryhelski
committed
Change veraPdf log mechanism, add log assert in checkValidatorLogsTest
DEVSIX-7172
1 parent 81dbdce commit 0fdc3a0

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

pdftest/src/main/java/com/itextpdf/test/pdfa/VeraPdfValidator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.test.pdfa;
4545

4646
import java.util.logging.Level;
47-
import org.verapdf.component.Log;
47+
import java.util.stream.Collectors;
4848
import org.verapdf.component.LogsSummary;
4949
import org.verapdf.component.LogsSummaryImpl;
5050
import org.verapdf.core.VeraPDFException;
@@ -103,14 +103,16 @@ public String validate(String filePath) {
103103
errorMessage = "VeraPDF execution failed - specified file is encrypted. See report: " + xmlReportPath;
104104
} else if (summary.getValidationSummary().getNonCompliantPdfaCount() != 0) {
105105
errorMessage = "VeraPDF verification failed. See verification results: " + xmlReportPath;
106-
} else if (logsSummary.getLogsCount() != 0) {
107-
errorMessage = "The following warnings and errors occurred while parsing current file:";
108-
for (Log log : logsSummary.getLogs()) {
109-
errorMessage += "\n" + log.getLevel() + ": " + log.getMessage();
110-
}
111-
errorMessage += "\nSee verification results:" + xmlReportPath;
112106
} else {
113107
System.out.println("VeraPDF verification finished. See verification report: " + xmlReportPath);
108+
109+
if (logsSummary.getLogsCount() != 0) {
110+
errorMessage = "The following warnings and errors were logged during validation:";
111+
errorMessage += logsSummary.getLogs().stream()
112+
.map(log -> "\n" + log.getLevel() + ": " + log.getMessage())
113+
.sorted()
114+
.collect(Collectors.joining());
115+
}
114116
}
115117
} catch (IOException | VeraPDFException exc) {
116118
errorMessage = "VeraPDF execution failed:\n" + exc.getMessage();

pdftest/src/test/java/com/itextpdf/test/VeraPdfLoggerValidationTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public void checkValidatorLogsTest() throws IOException {
7272
FileUtil.copy(SOURCE_FOLDER + fileNameWithWarnings, DESTINATION_FOLDER + fileNameWithWarnings);
7373
FileUtil.copy(SOURCE_FOLDER + fileNameWithoutWarnings, DESTINATION_FOLDER + fileNameWithoutWarnings);
7474

75-
Assert.assertNotNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithWarnings));
75+
String expectedWarningsForFileWithWarnings = "The following warnings and errors were logged during validation:\n"
76+
+ "WARNING: Invalid embedded cff font. Charset range exceeds number of glyphs\n"
77+
+ "WARNING: Missing OutputConditionIdentifier in an output intent dictionary\n"
78+
+ "WARNING: The Top DICT does not begin with ROS operator";
79+
Assert.assertEquals(expectedWarningsForFileWithWarnings, new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithWarnings));
80+
7681
//We check that the logs are empty after the first check
7782
Assert.assertNull(new VeraPdfValidator().validate(DESTINATION_FOLDER + fileNameWithoutWarnings));
7883
}

0 commit comments

Comments
 (0)