diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java b/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java index 79f7126f..1213930d 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/RegistrationRequest.java @@ -100,7 +100,7 @@ public void setAffiliation(String affiliation) { this.affiliation = affiliation; } - public Collection getAttrbutes() { + public Collection getAttributes() { return attrs; } diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java new file mode 100644 index 00000000..0ae4db8f --- /dev/null +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java @@ -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()); + } + } +} \ No newline at end of file diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java new file mode 100644 index 00000000..b2250ed5 --- /dev/null +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java @@ -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()); + } + } +} \ No newline at end of file