4
4
import com .itextpdf .basics .geom .Rectangle ;
5
5
import com .itextpdf .core .pdf .PdfReader ;
6
6
import com .itextpdf .core .pdf .PdfWriter ;
7
+ import com .itextpdf .core .utils .CompareTool ;
8
+ import com .itextpdf .test .annotations .type .IntegrationTest ;
9
+
7
10
import java .io .File ;
8
11
import java .io .FileInputStream ;
9
12
import java .io .IOException ;
16
19
import java .security .UnrecoverableKeyException ;
17
20
import java .security .cert .Certificate ;
18
21
import java .security .cert .CertificateException ;
22
+ import java .util .Arrays ;
23
+ import java .util .HashMap ;
24
+ import java .util .List ;
19
25
20
- import com .itextpdf .test .annotations .type .IntegrationTest ;
21
26
import org .bouncycastle .jce .provider .BouncyCastleProvider ;
27
+ import org .junit .Assert ;
22
28
import org .junit .Before ;
23
29
import org .junit .Test ;
24
30
import org .junit .experimental .categories .Category ;
25
31
26
32
33
+
27
34
//TODO: add some validation of results in future
28
35
@ Category (IntegrationTest .class )
29
36
public class SigningTest {
@@ -51,9 +58,10 @@ public void init() throws KeyStoreException, IOException, CertificateException,
51
58
}
52
59
53
60
@ Test
54
- public void simpleSigningTest () throws GeneralSecurityException , IOException {
61
+ public void simpleSigningTest () throws GeneralSecurityException , IOException , InterruptedException {
55
62
String src = sourceFolder + "simpleDocument.pdf" ;
56
- String dest = destinationFolder + "simpleSignature.pdf" ;
63
+ String fileName = "simpleSignature.pdf" ;
64
+ String dest = destinationFolder + fileName ;
57
65
58
66
int x = 36 ;
59
67
int y = 648 ;
@@ -65,28 +73,45 @@ public void simpleSigningTest() throws GeneralSecurityException, IOException {
65
73
sign (src , fieldName , dest , chain , pk ,
66
74
DigestAlgorithms .SHA256 , provider .getName (),
67
75
PdfSigner .CryptoStandard .CADES , "Test 1" , "TestCity" , rect , false );
76
+
77
+ Assert .assertNull (new CompareTool ().compareVisually (dest , sourceFolder + "cmp_" + fileName , destinationFolder , "diff_" ,
78
+ new HashMap <Integer , List <Rectangle >>() {{
79
+ put (1 , Arrays .asList (new Rectangle (67 , 690 , 148 , 15 )));
80
+ }}));
68
81
}
69
82
70
83
@ Test
71
- public void signingIntoExistingFieldTest01 () throws GeneralSecurityException , IOException {
84
+ public void signingIntoExistingFieldTest01 () throws GeneralSecurityException , IOException , InterruptedException {
72
85
String src = sourceFolder + "emptySignature01.pdf" ; //field is merged with widget and has /P key
73
- String dest = destinationFolder + "filledSignatureFields01.pdf" ;
86
+ String fileName = "filledSignatureFields01.pdf" ;
87
+ String dest = destinationFolder + fileName ;
74
88
75
89
String fieldName = "Signature1" ;
76
90
sign (src , fieldName , dest , chain , pk ,
77
91
DigestAlgorithms .SHA256 , provider .getName (),
78
92
PdfSigner .CryptoStandard .CADES , "Test 1" , "TestCity" , null , false );
93
+
94
+ Assert .assertNull (new CompareTool ().compareVisually (dest , sourceFolder + "cmp_" + fileName , destinationFolder , "diff_" ,
95
+ new HashMap <Integer , List <Rectangle >>() {{
96
+ put (1 , Arrays .asList (new Rectangle (67 , 725 , 148 , 15 )));
97
+ }}));
79
98
}
80
99
81
100
@ Test
82
- public void signingIntoExistingFieldTest02 () throws GeneralSecurityException , IOException {
101
+ public void signingIntoExistingFieldTest02 () throws GeneralSecurityException , IOException , InterruptedException {
83
102
String src = sourceFolder + "emptySignature02.pdf" ; //field is merged with widget and widget doesn't have /P key
84
- String dest = destinationFolder + "filledSignatureFields02.pdf" ;
103
+ String fileName = "filledSignatureFields02.pdf" ;
104
+ String dest = destinationFolder + fileName ;
85
105
86
106
String fieldName = "Signature1" ;
87
107
sign (src , fieldName , dest , chain , pk ,
88
108
DigestAlgorithms .SHA256 , provider .getName (),
89
109
PdfSigner .CryptoStandard .CADES , "Test 1" , "TestCity" , null , false );
110
+
111
+ Assert .assertNull (new CompareTool ().compareVisually (dest , sourceFolder + "cmp_" + fileName , destinationFolder , "diff_" ,
112
+ new HashMap <Integer , List <Rectangle >>() {{
113
+ put (1 , Arrays .asList (new Rectangle (67 , 725 , 148 , 15 )));
114
+ }}));
90
115
}
91
116
92
117
@ Test
0 commit comments