-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
John Harrison
committed
Jun 5, 2017
1 parent
f868689
commit 00e6c80
Showing
3 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright 2016, 2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.hyperledger.fabric_ca.sdk; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class RegistrationRequestTest { | ||
private static final String attrName = "some name"; | ||
private static final String attrValue = "some value"; | ||
private static final String regAffiliation = "corporation"; | ||
private static final String regCAName = "CA"; | ||
private static final String regID = "userid"; | ||
private static final String regSecret = "secret"; | ||
private static final String regType = "user"; | ||
|
||
private static final int regMaxEnrollments = 5; | ||
|
||
@Test | ||
public void testNewInstance() { | ||
|
||
try { | ||
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation); | ||
Assert.assertEquals(testRegisterReq.getEnrollmentID(), regID); | ||
Assert.assertEquals(testRegisterReq.getType(), regType); | ||
Assert.assertEquals(testRegisterReq.getMaxEnrollments(), 0); | ||
Assert.assertEquals(testRegisterReq.getAffiliation(), regAffiliation); | ||
Assert.assertTrue(testRegisterReq.getAttributes().isEmpty()); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewInstanceSetNullID() { | ||
|
||
try { | ||
new RegistrationRequest(null, regAffiliation); | ||
Assert.fail("Expected exception when null is specified for id"); | ||
|
||
} catch (Exception e) { | ||
Assert.assertEquals(e.getMessage(), "id may not be null"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewInstanceSetNullAffiliation() { | ||
|
||
try { | ||
new RegistrationRequest(regID, null); | ||
Assert.fail("Expected exception when null is specified for affiliation"); | ||
|
||
} catch (Exception e) { | ||
Assert.assertEquals(e.getMessage(), "affiliation may not be null"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRegisterReqSetGet() { | ||
|
||
try { | ||
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation); | ||
testRegisterReq.setEnrollmentID(regID + "update"); | ||
testRegisterReq.setSecret(regSecret); | ||
testRegisterReq.setMaxEnrollments(regMaxEnrollments); | ||
testRegisterReq.setType(regType); | ||
testRegisterReq.setAffiliation(regAffiliation + "update"); | ||
testRegisterReq.setCAName(regCAName); | ||
testRegisterReq.addAttribute(new Attribute(attrName, attrValue)); | ||
Assert.assertEquals(testRegisterReq.getEnrollmentID(), regID + "update"); | ||
Assert.assertEquals(testRegisterReq.getSecret(), regSecret); | ||
Assert.assertEquals(testRegisterReq.getType(), regType); | ||
Assert.assertEquals(testRegisterReq.getAffiliation(), regAffiliation + "update"); | ||
Assert.assertTrue(!testRegisterReq.getAttributes().isEmpty()); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRegisterReqToJson() { | ||
|
||
try { | ||
RegistrationRequest testRegisterReq = new RegistrationRequest(regID, regAffiliation); | ||
testRegisterReq.setEnrollmentID(regID + "update"); | ||
testRegisterReq.setSecret(regSecret); | ||
testRegisterReq.setMaxEnrollments(regMaxEnrollments); | ||
testRegisterReq.setType(regType); | ||
testRegisterReq.setAffiliation(regAffiliation + "update"); | ||
testRegisterReq.setCAName(regCAName); | ||
testRegisterReq.addAttribute(new Attribute(attrName, attrValue)); | ||
|
||
Assert.assertTrue(testRegisterReq.toJson().contains(regAffiliation + "update")); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright 2016, 2017 DTCC, Fujitsu Australia Software Technology, IBM - All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.hyperledger.fabric_ca.sdk; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class RevocationRequestTest { | ||
private static final String revCAName = "CA"; | ||
private static final String revEnrollmentID = "userid"; | ||
private static final String revSerialNmbr = "987654321"; | ||
private static final String revAKI = "123456789"; | ||
private static final String revReason = "compromised"; | ||
|
||
@Test | ||
public void testNewInstance() { | ||
|
||
try { | ||
RevocationRequest testRevocationReq = new RevocationRequest(revCAName, revEnrollmentID, revSerialNmbr, | ||
revAKI, revReason); | ||
Assert.assertEquals(testRevocationReq.getUser(), revEnrollmentID); | ||
Assert.assertEquals(testRevocationReq.getSerial(), revSerialNmbr); | ||
Assert.assertEquals(testRevocationReq.getAki(), revAKI); | ||
Assert.assertEquals(testRevocationReq.getReason(), revReason); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewInstanceSetNullIDSerialNmbr() { | ||
|
||
try { | ||
new RevocationRequest(revCAName, null, null, revAKI, revReason); | ||
Assert.fail("Expected exception when null is specified for serial number"); | ||
|
||
} catch (Exception e) { | ||
Assert.assertEquals(e.getMessage(), | ||
"Enrollment ID is empty, thus both aki and serial must have non-empty values"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewInstanceSetNullIDAKI() { | ||
|
||
try { | ||
new RevocationRequest(revCAName, null, revSerialNmbr, null, revReason); | ||
Assert.fail("Expected exception when null is specified for AKI"); | ||
|
||
} catch (Exception e) { | ||
Assert.assertEquals(e.getMessage(), | ||
"Enrollment ID is empty, thus both aki and serial must have non-empty values"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRevocationReqSetGet() { | ||
|
||
try { | ||
RevocationRequest testRevocationReq = new RevocationRequest(revCAName, revEnrollmentID, revSerialNmbr, | ||
revAKI, revReason); | ||
testRevocationReq.setUser(revEnrollmentID + "update"); | ||
testRevocationReq.setSerial(revSerialNmbr + "000"); | ||
testRevocationReq.setAki(revAKI + "000"); | ||
testRevocationReq.setReason(revReason + "update"); | ||
Assert.assertEquals(testRevocationReq.getUser(), revEnrollmentID + "update"); | ||
Assert.assertEquals(testRevocationReq.getSerial(), revSerialNmbr + "000"); | ||
Assert.assertEquals(testRevocationReq.getAki(), revAKI + "000"); | ||
Assert.assertEquals(testRevocationReq.getReason(), revReason + "update"); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRevocationReqToJsonNullID() { | ||
|
||
try { | ||
RevocationRequest testRevocationReq = new RevocationRequest(revCAName, null, revSerialNmbr, revAKI, | ||
revReason); | ||
testRevocationReq.setSerial(revSerialNmbr); | ||
testRevocationReq.setAki(revAKI + "000"); | ||
testRevocationReq.setReason(revReason + "update"); | ||
|
||
Assert.assertTrue(testRevocationReq.toJson().contains("0" + revSerialNmbr)); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRevocationReqToJson() { | ||
|
||
try { | ||
RevocationRequest testRevocationReq = new RevocationRequest(revCAName, revEnrollmentID, revSerialNmbr, | ||
revAKI, revReason); | ||
testRevocationReq.setUser(revEnrollmentID + "update"); | ||
testRevocationReq.setSerial(revSerialNmbr + "000"); | ||
testRevocationReq.setAki(revAKI + "000"); | ||
testRevocationReq.setReason(revReason + "update"); | ||
|
||
Assert.assertTrue(testRevocationReq.toJson().contains(revReason + "update")); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
} |