1
+ /*
2
+ * Copyright 2016, 2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+
15
+ package org .hyperledger .fabric_ca .sdk ;
16
+
17
+ import org .junit .Assert ;
18
+ import org .junit .Test ;
19
+
20
+ public class RevocationRequestTest {
21
+ private static final String revCAName = "CA" ;
22
+ private static final String revEnrollmentID = "userid" ;
23
+ private static final String revSerialNmbr = "987654321" ;
24
+ private static final String revAKI = "123456789" ;
25
+ private static final String revReason = "compromised" ;
26
+
27
+ @ Test
28
+ public void testNewInstance () {
29
+
30
+ try {
31
+ RevocationRequest testRevocationReq = new RevocationRequest (revCAName , revEnrollmentID , revSerialNmbr ,
32
+ revAKI , revReason );
33
+ Assert .assertEquals (testRevocationReq .getUser (), revEnrollmentID );
34
+ Assert .assertEquals (testRevocationReq .getSerial (), revSerialNmbr );
35
+ Assert .assertEquals (testRevocationReq .getAki (), revAKI );
36
+ Assert .assertEquals (testRevocationReq .getReason (), revReason );
37
+
38
+ } catch (Exception e ) {
39
+ Assert .fail ("Unexpected Exception " + e .getMessage ());
40
+ }
41
+ }
42
+
43
+ @ Test
44
+ public void testNewInstanceSetNullIDSerialNmbr () {
45
+
46
+ try {
47
+ new RevocationRequest (revCAName , null , null , revAKI , revReason );
48
+ Assert .fail ("Expected exception when null is specified for serial number" );
49
+
50
+ } catch (Exception e ) {
51
+ Assert .assertEquals (e .getMessage (),
52
+ "Enrollment ID is empty, thus both aki and serial must have non-empty values" );
53
+ }
54
+ }
55
+
56
+ @ Test
57
+ public void testNewInstanceSetNullIDAKI () {
58
+
59
+ try {
60
+ new RevocationRequest (revCAName , null , revSerialNmbr , null , revReason );
61
+ Assert .fail ("Expected exception when null is specified for AKI" );
62
+
63
+ } catch (Exception e ) {
64
+ Assert .assertEquals (e .getMessage (),
65
+ "Enrollment ID is empty, thus both aki and serial must have non-empty values" );
66
+ }
67
+ }
68
+
69
+ @ Test
70
+ public void testRevocationReqSetGet () {
71
+
72
+ try {
73
+ RevocationRequest testRevocationReq = new RevocationRequest (revCAName , revEnrollmentID , revSerialNmbr ,
74
+ revAKI , revReason );
75
+ testRevocationReq .setUser (revEnrollmentID + "update" );
76
+ testRevocationReq .setSerial (revSerialNmbr + "000" );
77
+ testRevocationReq .setAki (revAKI + "000" );
78
+ testRevocationReq .setReason (revReason + "update" );
79
+ Assert .assertEquals (testRevocationReq .getUser (), revEnrollmentID + "update" );
80
+ Assert .assertEquals (testRevocationReq .getSerial (), revSerialNmbr + "000" );
81
+ Assert .assertEquals (testRevocationReq .getAki (), revAKI + "000" );
82
+ Assert .assertEquals (testRevocationReq .getReason (), revReason + "update" );
83
+
84
+ } catch (Exception e ) {
85
+ Assert .fail ("Unexpected Exception " + e .getMessage ());
86
+ }
87
+ }
88
+
89
+ @ Test
90
+ public void testRevocationReqToJsonNullID () {
91
+
92
+ try {
93
+ RevocationRequest testRevocationReq = new RevocationRequest (revCAName , null , revSerialNmbr , revAKI ,
94
+ revReason );
95
+ testRevocationReq .setSerial (revSerialNmbr );
96
+ testRevocationReq .setAki (revAKI + "000" );
97
+ testRevocationReq .setReason (revReason + "update" );
98
+
99
+ Assert .assertTrue (testRevocationReq .toJson ().contains ("0" + revSerialNmbr ));
100
+
101
+ } catch (Exception e ) {
102
+ Assert .fail ("Unexpected Exception " + e .getMessage ());
103
+ }
104
+ }
105
+
106
+ @ Test
107
+ public void testRevocationReqToJson () {
108
+
109
+ try {
110
+ RevocationRequest testRevocationReq = new RevocationRequest (revCAName , revEnrollmentID , revSerialNmbr ,
111
+ revAKI , revReason );
112
+ testRevocationReq .setUser (revEnrollmentID + "update" );
113
+ testRevocationReq .setSerial (revSerialNmbr + "000" );
114
+ testRevocationReq .setAki (revAKI + "000" );
115
+ testRevocationReq .setReason (revReason + "update" );
116
+
117
+ Assert .assertTrue (testRevocationReq .toJson ().contains (revReason + "update" ));
118
+
119
+ } catch (Exception e ) {
120
+ Assert .fail ("Unexpected Exception " + e .getMessage ());
121
+ }
122
+ }
123
+ }
0 commit comments