-
Notifications
You must be signed in to change notification settings - Fork 707
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
This change improves the code coverage of the org.hyperledger.fabric_ca.sdk package. Additional CRs will follow. Change-Id: I2b9c626a35c1cd8662950e986caab7648fbb241b Signed-off-by: John Harrison <harrijk63@gmail.com>
- Loading branch information
John Harrison
committed
Jun 5, 2017
1 parent
5ced72d
commit f868689
Showing
3 changed files
with
158 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ target | |
*.class | ||
.idea/ | ||
*.iml | ||
*.resources.prefs |
54 changes: 54 additions & 0 deletions
54
src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.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,54 @@ | ||
/* | ||
* 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 javax.json.JsonObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class AttributeTest { | ||
private static final String attrName = "some name"; | ||
private static final String attrValue = "some value"; | ||
|
||
@Test | ||
public void testNewInstance() { | ||
|
||
try { | ||
Attribute testAttribute = new Attribute(attrName, attrValue); | ||
Assert.assertNotNull(testAttribute.getName()); | ||
Assert.assertSame(testAttribute.getName(), attrName); | ||
Assert.assertNotNull(testAttribute.getValue()); | ||
Assert.assertSame(testAttribute.getValue(), attrValue); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testJsonBuild() { | ||
|
||
try { | ||
Attribute testAttribute = new Attribute(attrName, attrValue); | ||
JsonObject attrJson = testAttribute.toJsonObject(); | ||
Assert.assertNotNull(attrJson); | ||
Assert.assertEquals(attrJson.getString("name"), attrName); | ||
Assert.assertEquals(attrJson.getString("value"), attrValue); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.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,103 @@ | ||
/* | ||
* 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 java.security.KeyPair; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class EnrollmentRequestTest { | ||
private static final String caName = "certsInc"; | ||
private static final String csr = "11436845810603"; | ||
private static final String profile = "test profile"; | ||
private static final String label = "test label"; | ||
private static final KeyPair keyPair = null; | ||
|
||
@Test | ||
public void testNewInstanceEmpty() { | ||
|
||
try { | ||
EnrollmentRequest testEnrollReq = new EnrollmentRequest(); | ||
Assert.assertNull(testEnrollReq.getCsr()); | ||
Assert.assertTrue(testEnrollReq.getHosts().isEmpty()); | ||
Assert.assertNull(testEnrollReq.getProfile()); | ||
Assert.assertNull(testEnrollReq.getLabel()); | ||
Assert.assertNull(testEnrollReq.getKeyPair()); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewInstanceParms() { | ||
|
||
try { | ||
EnrollmentRequest testEnrollReq = new EnrollmentRequest(profile, label, keyPair); | ||
Assert.assertNull(testEnrollReq.getCsr()); | ||
Assert.assertTrue(testEnrollReq.getHosts().isEmpty()); | ||
Assert.assertEquals(testEnrollReq.getProfile(), profile); | ||
Assert.assertEquals(testEnrollReq.getLabel(), label); | ||
Assert.assertNull(testEnrollReq.getKeyPair()); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testEnrollReqSetGet() { | ||
|
||
try { | ||
EnrollmentRequest testEnrollReq = new EnrollmentRequest(); | ||
testEnrollReq.addHost("d.com"); | ||
testEnrollReq.setCsr(csr); | ||
testEnrollReq.setCSR(csr); // Unsure why there are two methods that | ||
// set csr | ||
testEnrollReq.setProfile(profile); | ||
testEnrollReq.setLabel(label); | ||
testEnrollReq.setKeyPair(null); | ||
testEnrollReq.setCAName(caName); | ||
Assert.assertEquals(testEnrollReq.getCsr(), csr); | ||
Assert.assertTrue(testEnrollReq.getHosts().contains("d.com")); | ||
Assert.assertEquals(testEnrollReq.getProfile(), profile); | ||
Assert.assertEquals(testEnrollReq.getLabel(), label); | ||
Assert.assertNull(testEnrollReq.getKeyPair()); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testEnrollReqToJson() { | ||
|
||
try { | ||
EnrollmentRequest testEnrollReq = new EnrollmentRequest(); | ||
testEnrollReq.addHost("d.com"); | ||
testEnrollReq.setCsr(csr); | ||
testEnrollReq.setCSR(csr); // Two setters perform the same function | ||
testEnrollReq.setProfile(profile); | ||
testEnrollReq.setLabel(label); | ||
testEnrollReq.setKeyPair(null); | ||
testEnrollReq.setCAName(caName); | ||
|
||
Assert.assertTrue(testEnrollReq.toJson().contains(csr)); | ||
|
||
} catch (Exception e) { | ||
Assert.fail("Unexpected Exception " + e.getMessage()); | ||
} | ||
} | ||
} |