Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 00e6c80

Browse files
author
John Harrison
committed
[FAB-4363] Increase fabric-sdk-java code coverage #2
This change improves the code coverage of the org.hyperledger.fabric_ca.sdk package. Classes covered: RegistrationRequest RevocationRequest Change-Id: I5a70c2e41df60ec4cf81d99bfe2c807a51885ba6 Signed-off-by: John Harrison <harrijk63@gmail.com>
1 parent f868689 commit 00e6c80

File tree

3 files changed

+237
-1
lines changed

3 files changed

+237
-1
lines changed

src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void setAffiliation(String affiliation) {
100100
this.affiliation = affiliation;
101101
}
102102

103-
public Collection<Attribute> getAttrbutes() {
103+
public Collection<Attribute> getAttributes() {
104104
return attrs;
105105
}
106106

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 RegistrationRequestTest {
21+
private static final String attrName = "some name";
22+
private static final String attrValue = "some value";
23+
private static final String regAffiliation = "corporation";
24+
private static final String regCAName = "CA";
25+
private static final String regID = "userid";
26+
private static final String regSecret = "secret";
27+
private static final String regType = "user";
28+
29+
private static final int regMaxEnrollments = 5;
30+
31+
@Test
32+
public void testNewInstance() {
33+
34+
try {
35+
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation);
36+
Assert.assertEquals(testRegisterReq.getEnrollmentID(), regID);
37+
Assert.assertEquals(testRegisterReq.getType(), regType);
38+
Assert.assertEquals(testRegisterReq.getMaxEnrollments(), 0);
39+
Assert.assertEquals(testRegisterReq.getAffiliation(), regAffiliation);
40+
Assert.assertTrue(testRegisterReq.getAttributes().isEmpty());
41+
42+
} catch (Exception e) {
43+
Assert.fail("Unexpected Exception " + e.getMessage());
44+
}
45+
}
46+
47+
@Test
48+
public void testNewInstanceSetNullID() {
49+
50+
try {
51+
new RegistrationRequest(null, regAffiliation);
52+
Assert.fail("Expected exception when null is specified for id");
53+
54+
} catch (Exception e) {
55+
Assert.assertEquals(e.getMessage(), "id may not be null");
56+
}
57+
}
58+
59+
@Test
60+
public void testNewInstanceSetNullAffiliation() {
61+
62+
try {
63+
new RegistrationRequest(regID, null);
64+
Assert.fail("Expected exception when null is specified for affiliation");
65+
66+
} catch (Exception e) {
67+
Assert.assertEquals(e.getMessage(), "affiliation may not be null");
68+
}
69+
}
70+
71+
@Test
72+
public void testRegisterReqSetGet() {
73+
74+
try {
75+
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation);
76+
testRegisterReq.setEnrollmentID(regID + "update");
77+
testRegisterReq.setSecret(regSecret);
78+
testRegisterReq.setMaxEnrollments(regMaxEnrollments);
79+
testRegisterReq.setType(regType);
80+
testRegisterReq.setAffiliation(regAffiliation + "update");
81+
testRegisterReq.setCAName(regCAName);
82+
testRegisterReq.addAttribute(new Attribute(attrName, attrValue));
83+
Assert.assertEquals(testRegisterReq.getEnrollmentID(), regID + "update");
84+
Assert.assertEquals(testRegisterReq.getSecret(), regSecret);
85+
Assert.assertEquals(testRegisterReq.getType(), regType);
86+
Assert.assertEquals(testRegisterReq.getAffiliation(), regAffiliation + "update");
87+
Assert.assertTrue(!testRegisterReq.getAttributes().isEmpty());
88+
89+
} catch (Exception e) {
90+
Assert.fail("Unexpected Exception " + e.getMessage());
91+
}
92+
}
93+
94+
@Test
95+
public void testRegisterReqToJson() {
96+
97+
try {
98+
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation);
99+
testRegisterReq.setEnrollmentID(regID + "update");
100+
testRegisterReq.setSecret(regSecret);
101+
testRegisterReq.setMaxEnrollments(regMaxEnrollments);
102+
testRegisterReq.setType(regType);
103+
testRegisterReq.setAffiliation(regAffiliation + "update");
104+
testRegisterReq.setCAName(regCAName);
105+
testRegisterReq.addAttribute(new Attribute(attrName, attrValue));
106+
107+
Assert.assertTrue(testRegisterReq.toJson().contains(regAffiliation + "update"));
108+
109+
} catch (Exception e) {
110+
Assert.fail("Unexpected Exception " + e.getMessage());
111+
}
112+
}
113+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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

Comments
 (0)