diff --git a/.gitignore b/.gitignore index 0a8719d1..9b86191a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target *.class .idea/ *.iml +*.resources.prefs diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java new file mode 100644 index 00000000..f9db609b --- /dev/null +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java @@ -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()); + } + } +} diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.java new file mode 100644 index 00000000..5f6075cc --- /dev/null +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.java @@ -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()); + } + } +} \ No newline at end of file