Skip to content

Commit 4510043

Browse files
author
Kate Ivanova
committed
Add new Pdfa2Checker and Pdfa3Checker tests
1. Create PdfA3CatalogCheckTest class 2. Add new tests: PdfA2CatalogCheckTest#checkAbsenceOfOptionalConfigEntry; PdfA2CatalogCheckTest#checkAbsenceOfOptionalOrderEntry; PdfA3CatalogCheckTest#checkAbsenceOfConfigEntry; PdfA3CatalogCheckTest#checkAbsenceOfOrderEntry. DEVSIX-3206
1 parent 1d70930 commit 4510043

File tree

2 files changed

+218
-0
lines changed

2 files changed

+218
-0
lines changed

pdfa/src/test/java/com/itextpdf/pdfa/PdfA2CatalogCheckTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,80 @@ public void catalogCheck10() throws FileNotFoundException {
384384
doc.close();
385385
}
386386

387+
@Test
388+
//TODO Remove expected exception when DEVSIX-3206 will be fixed
389+
public void checkAbsenceOfOptionalConfigEntry() throws FileNotFoundException {
390+
junitExpectedException.expect(PdfAConformanceException.class);
391+
junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS);
392+
393+
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
394+
395+
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
396+
397+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B,
398+
new PdfOutputIntent("Custom", "",
399+
"http://www.color.org", "sRGB IEC61966-2.1", is));
400+
doc.addNewPage();
401+
402+
PdfDictionary ocProperties = new PdfDictionary();
403+
404+
PdfDictionary d = new PdfDictionary();
405+
d.put(PdfName.Name, new PdfString("CustomName"));
406+
407+
PdfDictionary orderItem = new PdfDictionary();
408+
orderItem.put(PdfName.Name, new PdfString("CustomName2"));
409+
410+
PdfArray ocgs = new PdfArray();
411+
ocgs.add(orderItem);
412+
413+
ocProperties.put(PdfName.OCGs, ocgs);
414+
ocProperties.put(PdfName.D, d);
415+
doc.getCatalog().put(PdfName.OCProperties, ocProperties);
416+
417+
doc.close();
418+
}
419+
420+
@Test
421+
//TODO Remove expected exception when DEVSIX-3206 will be fixed
422+
public void checkAbsenceOfOptionalOrderEntry() throws FileNotFoundException {
423+
junitExpectedException.expect(PdfAConformanceException.class);
424+
junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS);
425+
426+
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
427+
428+
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
429+
430+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B,
431+
new PdfOutputIntent("Custom", "",
432+
"http://www.color.org", "sRGB IEC61966-2.1", is));
433+
doc.addNewPage();
434+
435+
PdfDictionary ocProperties = new PdfDictionary();
436+
437+
PdfDictionary d = new PdfDictionary();
438+
d.put(PdfName.Name, new PdfString("CustomName"));
439+
440+
PdfDictionary orderItem = new PdfDictionary();
441+
orderItem.put(PdfName.Name, new PdfString("CustomName2"));
442+
443+
PdfArray ocgs = new PdfArray();
444+
ocgs.add(orderItem);
445+
446+
PdfArray configs = new PdfArray();
447+
448+
PdfDictionary config = new PdfDictionary();
449+
config.put(PdfName.Name, new PdfString("CustomName1"));
450+
451+
configs.add(config);
452+
453+
ocProperties.put(PdfName.OCGs, ocgs);
454+
ocProperties.put(PdfName.D, d);
455+
ocProperties.put(PdfName.Configs, configs);
456+
doc.getCatalog().put(PdfName.OCProperties, ocProperties);
457+
458+
doc.close();
459+
}
460+
387461
private void compareResult(String outPdf, String cmpPdf) throws IOException, InterruptedException {
388462
String result = new CompareTool().compareByContent(outPdf, cmpPdf, destinationFolder, "diff_");
389463
if (result != null) {
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.pdfa;
44+
45+
import com.itextpdf.io.source.ByteArrayOutputStream;
46+
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
47+
import com.itextpdf.kernel.pdf.PdfArray;
48+
import com.itextpdf.kernel.pdf.PdfDictionary;
49+
import com.itextpdf.kernel.pdf.PdfName;
50+
import com.itextpdf.kernel.pdf.PdfOutputIntent;
51+
import com.itextpdf.kernel.pdf.PdfString;
52+
import com.itextpdf.kernel.pdf.PdfWriter;
53+
import com.itextpdf.test.ExtendedITextTest;
54+
import com.itextpdf.test.annotations.type.IntegrationTest;
55+
56+
import java.io.FileInputStream;
57+
import java.io.FileNotFoundException;
58+
import java.io.InputStream;
59+
import org.junit.Rule;
60+
import org.junit.Test;
61+
import org.junit.experimental.categories.Category;
62+
import org.junit.rules.ExpectedException;
63+
64+
@Category(IntegrationTest.class)
65+
public class PdfA3CatalogCheckTest extends ExtendedITextTest {
66+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/pdfa/";
67+
68+
@Rule
69+
public ExpectedException junitExpectedException = ExpectedException.none();
70+
71+
@Test
72+
//TODO Remove expected exception when DEVSIX-3206 will be fixed
73+
public void checkAbsenceOfConfigEntry() throws FileNotFoundException {
74+
junitExpectedException.expect(PdfAConformanceException.class);
75+
junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS);
76+
77+
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
78+
79+
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
80+
81+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B,
82+
new PdfOutputIntent("Custom", "",
83+
"http://www.color.org", "sRGB IEC61966-2.1", is));
84+
doc.addNewPage();
85+
86+
PdfDictionary ocProperties = new PdfDictionary();
87+
88+
PdfDictionary d = new PdfDictionary();
89+
d.put(PdfName.Name, new PdfString("CustomName"));
90+
91+
PdfDictionary orderItem = new PdfDictionary();
92+
orderItem.put(PdfName.Name, new PdfString("CustomName2"));
93+
94+
PdfArray ocgs = new PdfArray();
95+
ocgs.add(orderItem);
96+
97+
ocProperties.put(PdfName.OCGs, ocgs);
98+
ocProperties.put(PdfName.D, d);
99+
doc.getCatalog().put(PdfName.OCProperties, ocProperties);
100+
101+
doc.close();
102+
}
103+
104+
@Test
105+
//TODO Remove expected exception when DEVSIX-3206 will be fixed
106+
public void checkAbsenceOfOrderEntry() throws FileNotFoundException {
107+
junitExpectedException.expect(PdfAConformanceException.class);
108+
junitExpectedException.expectMessage(PdfAConformanceException.ORDER_ARRAY_SHALL_CONTAIN_REFERENCES_TO_ALL_OCGS);
109+
110+
PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
111+
112+
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
113+
114+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B,
115+
new PdfOutputIntent("Custom", "",
116+
"http://www.color.org", "sRGB IEC61966-2.1", is));
117+
doc.addNewPage();
118+
119+
PdfDictionary ocProperties = new PdfDictionary();
120+
121+
PdfDictionary d = new PdfDictionary();
122+
d.put(PdfName.Name, new PdfString("CustomName"));
123+
124+
PdfDictionary orderItem = new PdfDictionary();
125+
orderItem.put(PdfName.Name, new PdfString("CustomName2"));
126+
127+
PdfArray ocgs = new PdfArray();
128+
ocgs.add(orderItem);
129+
130+
PdfArray configs = new PdfArray();
131+
132+
PdfDictionary config = new PdfDictionary();
133+
config.put(PdfName.Name, new PdfString("CustomName1"));
134+
135+
configs.add(config);
136+
137+
ocProperties.put(PdfName.OCGs, ocgs);
138+
ocProperties.put(PdfName.D, d);
139+
ocProperties.put(PdfName.Configs, configs);
140+
doc.getCatalog().put(PdfName.OCProperties, ocProperties);
141+
142+
doc.close();
143+
}
144+
}

0 commit comments

Comments
 (0)