From 9992851d8cf26e06718490213e6d446a890cd0ed Mon Sep 17 00:00:00 2001 From: Chris Murphy Date: Mon, 12 Jun 2017 10:35:29 +1000 Subject: [PATCH] FAB-4536 Enable checkstyle for test suite . Modified pom.xml to include the test directory . Fixed all reported checkstyle errors . These were mostly whitespace and import order issues . Explicitly disabled checkstyle for End2endAndBackAgainIT.runChannel as the method needs to be this long for clarity . Added a private constructor into one of the Utils classes Change-Id: Ib5533a6771da97dc203e35dfe40a97284d3b739e Signed-off-by: Chris Murphy --- pom.xml | 1 + .../sdkintegration/javacc/example_cc/pom.xml | 2 +- .../fabric/sdk/PeerClientTest.java | 188 ++++++++-------- .../sdk/security/CryptoPrimitivesTest.java | 6 +- .../fabric/sdk/testutils/TestConfig.java | 4 +- .../sdkintegration/End2endAndBackAgainIT.java | 19 +- .../fabric/sdkintegration/End2endIT.java | 2 +- .../fabric/sdkintegration/SampleOrg.java | 8 +- .../fabric/sdkintegration/Util.java | 9 +- .../fabric_ca/sdk/AttributeTest.java | 66 +++--- .../fabric_ca/sdk/EnrollmentRequestTest.java | 164 +++++++------- .../sdk/RegistrationRequestTest.java | 186 ++++++++-------- .../fabric_ca/sdk/RevocationRequestTest.java | 206 +++++++++--------- .../sdkintegration/HFCAClientEnrollIT.java | 4 +- 14 files changed, 434 insertions(+), 431 deletions(-) diff --git a/pom.xml b/pom.xml index 07eda745..8fca5e86 100644 --- a/pom.xml +++ b/pom.xml @@ -310,6 +310,7 @@ true ${project.build.sourceDirectory} checkstyle-config.xml + true diff --git a/src/test/fixture/sdkintegration/javacc/example_cc/pom.xml b/src/test/fixture/sdkintegration/javacc/example_cc/pom.xml index 99047b87..6c9d1809 100644 --- a/src/test/fixture/sdkintegration/javacc/example_cc/pom.xml +++ b/src/test/fixture/sdkintegration/javacc/example_cc/pom.xml @@ -65,7 +65,7 @@ limitations under the License. - + diff --git a/src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java b/src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java index f718270d..5d258b7b 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java @@ -28,108 +28,108 @@ public class PeerClientTest { -// static Channel testChain = null; -// static ChaincodeResponse deployResponse = null; -// static ChaincodeResponse javaDeployResponse = null; +// static Channel testChain = null; +// static ChaincodeResponse deployResponse = null; +// static ChaincodeResponse javaDeployResponse = null; // -// @BeforeClass -// public static void setupChain() { -// testChain = new Channel("chain1"); -// try { -// testChain.setMemberServicesUrl("grpc://localhost:7054", null); -// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties")); -// testChain.addPeer("grpc://localhost:7051", null); -// //testChain.setDevMode(true); -// SampleUser registrar = testChain.getUser("admin"); -// if (!registrar.isEnrolled()) { -// registrar = testChain.enroll("admin", "Xurw3yU9zI0l"); -// } -// testChain.setRegistrar(registrar); -// deployResponse = deploy(); -// javaDeployResponse = deployJava(); -// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call -// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) { -// cex.printStackTrace();// TODO: Handle the exception properly -// } -// } +// @BeforeClass +// public static void setupChain() { +// testChain = new Channel("chain1"); +// try { +// testChain.setMemberServicesUrl("grpc://localhost:7054", null); +// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties")); +// testChain.addPeer("grpc://localhost:7051", null); +// //testChain.setDevMode(true); +// SampleUser registrar = testChain.getUser("admin"); +// if (!registrar.isEnrolled()) { +// registrar = testChain.enroll("admin", "Xurw3yU9zI0l"); +// } +// testChain.setRegistrar(registrar); +// deployResponse = deploy(); +// javaDeployResponse = deployJava(); +// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call +// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) { +// cex.printStackTrace();// TODO: Handle the exception properly +// } +// } // // -// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException { -// InstallProposalRequest request = new InstallProposalRequest(); -// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"); -// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); -// SampleUser user = getUser("User1", "bank_a"); -// request.setChaincodeName("mycc"); -// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG); -// return user.deploy(request); -// } +// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException { +// InstallProposalRequest request = new InstallProposalRequest(); +// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"); +// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); +// SampleUser user = getUser("User1", "bank_a"); +// request.setChaincodeName("mycc"); +// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG); +// return user.deploy(request); +// } // -// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException { -// InstallProposalRequest request = new InstallProposalRequest(); -// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example"); -// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); -// SampleUser user = getUser("User1", "bank_a"); -// request.setChaincodeName("myccj"); -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); -// return user.deploy(request); +// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException { +// InstallProposalRequest request = new InstallProposalRequest(); +// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example"); +// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000"))); +// SampleUser user = getUser("User1", "bank_a"); +// request.setChaincodeName("myccj"); +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); +// return user.deploy(request); // -// } +// } // -// @Test -// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException { -// testInvoke(); // the amount is stored -// QueryRequest request = new QueryRequest(); -// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); -// request.setChaincodeID(deployResponse.getChaincodeID()); -// request.setChaincodeName(deployResponse.getChaincodeID()); -// SampleUser user = getUser("User1", "bank_a"); -// user.query(request); -// } +// @Test +// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException { +// testInvoke(); // the amount is stored +// QueryRequest request = new QueryRequest(); +// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); +// request.setChaincodeID(deployResponse.getChaincodeID()); +// request.setChaincodeName(deployResponse.getChaincodeID()); +// SampleUser user = getUser("User1", "bank_a"); +// user.query(request); +// } // -// @Test -// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException { -// InvokeRequest request = new InvokeRequest(); -// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); -// request.setChaincodeID(deployResponse.getChaincodeID()); -// request.setChaincodeName(deployResponse.getChaincodeID()); -// SampleUser user = getUser("User1", "bank_a"); -// user.invoke(request); -// } +// @Test +// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException { +// InvokeRequest request = new InvokeRequest(); +// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); +// request.setChaincodeID(deployResponse.getChaincodeID()); +// request.setChaincodeName(deployResponse.getChaincodeID()); +// SampleUser user = getUser("User1", "bank_a"); +// user.invoke(request); +// } // -// @Test -// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException { -// testInvokeJava(); -// QueryRequest request = new QueryRequest(); -// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); -// request.setChaincodeID(javaDeployResponse.getChaincodeID()); -// request.setChaincodeName(javaDeployResponse.getChaincodeID()); -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); -// SampleUser user = getUser("User1", "bank_a"); -// user.query(request); -// } +// @Test +// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException { +// testInvokeJava(); +// QueryRequest request = new QueryRequest(); +// request.setArgs(new ArrayList<>(Arrays.asList("query", "a"))); +// request.setChaincodeID(javaDeployResponse.getChaincodeID()); +// request.setChaincodeName(javaDeployResponse.getChaincodeID()); +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); +// SampleUser user = getUser("User1", "bank_a"); +// user.query(request); +// } // -// @Test -// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException { -// InvokeRequest request = new InvokeRequest(); -// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); -// request.setChaincodeID(javaDeployResponse.getChaincodeID()); -// request.setChaincodeName(javaDeployResponse.getChaincodeID()); -// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); -// SampleUser user = getUser("User1", "bank_a"); -// user.invoke(request); -// } +// @Test +// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException { +// InvokeRequest request = new InvokeRequest(); +// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200"))); +// request.setChaincodeID(javaDeployResponse.getChaincodeID()); +// request.setChaincodeName(javaDeployResponse.getChaincodeID()); +// request.setChaincodeLanguage(ChaincodeLanguage.JAVA); +// SampleUser user = getUser("User1", "bank_a"); +// user.invoke(request); +// } // -// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException { -// SampleUser user = testChain.getUser(enrollmentId); -// if (!user.isRegistered()) { -// RegistrationRequest registrationRequest = new RegistrationRequest(); -// registrationRequest.setEnrollmentID(enrollmentId); -// registrationRequest.setAffiliation(affiliation); -// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest? -// user = testChain.registerAndEnroll(registrationRequest); -// } else if (!user.isEnrolled()) { -// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret()); -// } -// return user; -// } +// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException { +// SampleUser user = testChain.getUser(enrollmentId); +// if (!user.isRegistered()) { +// RegistrationRequest registrationRequest = new RegistrationRequest(); +// registrationRequest.setEnrollmentID(enrollmentId); +// registrationRequest.setAffiliation(affiliation); +// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest? +// user = testChain.registerAndEnroll(registrationRequest); +// } else if (!user.isEnrolled()) { +// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret()); +// } +// return user; +// } } diff --git a/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java b/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java index 3bd70c77..e0e96243 100755 --- a/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java @@ -272,7 +272,7 @@ public void testAddCACertificateToTrustStoreNoCert() throws InvalidArgumentExcep @Test(expected = InvalidArgumentException.class) public void testAddCACertsNullInput() throws Exception { - crypto.addCACertificateToTrustStore((File)null, null);; + crypto.addCACertificateToTrustStore((File) null, null); } @Test(expected = CryptoException.class) @@ -368,7 +368,7 @@ public void testValidateNotSignedCertificate() { } @Test - public void testValidateInvalidCertificate() throws IOException, CertificateException{ + public void testValidateInvalidCertificate() throws IOException, CertificateException { BufferedInputStream pem = new BufferedInputStream(new ByteArrayInputStream(invalidPemCert)); assertFalse(crypto.validateCertificate(invalidPemCert)); @@ -481,7 +481,7 @@ public void testSign() { @Test - public void testKeyGen() throws CryptoException{ + public void testKeyGen() throws CryptoException { Assert.assertNotNull(crypto.keyGen()); Assert.assertSame(KeyPair.class, crypto.keyGen().getClass()); } diff --git a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java index 757dad21..bd4b5fb1 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java +++ b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java @@ -64,11 +64,11 @@ public class TestConfig { private static final String INTEGRATIONTESTSTLS = PROPBASE + "integrationtests.tls"; private static TestConfig config; - private final static Properties sdkProperties = new Properties(); + private static final Properties sdkProperties = new Properties(); private final boolean runningTLS; private final boolean runningFabricCATLS; private final boolean runningFabricTLS; - private final static HashMap sampleOrgs = new HashMap<>(); + private static final HashMap sampleOrgs = new HashMap<>(); private TestConfig() { File loadFile; diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java index 0439c16b..ef56f9c7 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java @@ -17,10 +17,8 @@ import java.io.File; import java.net.MalformedURLException; import java.util.Collection; -import java.util.Hashtable; import java.util.LinkedList; import java.util.List; -import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -177,6 +175,9 @@ public void setup() { } } + // Disable MethodLength as this method is for instructional purposes and hence + // we don't want to split it into smaller pieces + // CHECKSTYLE:OFF: MethodLength void runChannel(HFClient client, Channel channel, SampleOrg sampleOrg, final int delta) { final String channelName = channel.getName(); try { @@ -272,7 +273,7 @@ void runChannel(HFClient client, Channel channel, SampleOrg sampleOrg, final int upgradeProposalRequest.setChaincodeID(chaincodeID_11); upgradeProposalRequest.setProposalWaitTime(testConfig.getProposalWaitTime()); upgradeProposalRequest.setFcn("init"); - upgradeProposalRequest.setArgs(new String[] {});// no arguments don't change the ledger see chaincode. + upgradeProposalRequest.setArgs(new String[] {}); // no arguments don't change the ledger see chaincode. ChaincodeEndorsementPolicy chaincodeEndorsementPolicy; @@ -576,16 +577,16 @@ private void waitOnFabric(int additional) { // } } - private static boolean checkInstalledChaincode(HFClient client, Peer peer, String cc_name, String cc_path, String cc_version) throws InvalidArgumentException, ProposalException { + private static boolean checkInstalledChaincode(HFClient client, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException { - out("Checking installed chaincode: %s, at version: %s, on peer: %s", cc_name, cc_version, peer.getName()); + out("Checking installed chaincode: %s, at version: %s, on peer: %s", ccName, ccVersion, peer.getName()); List ccinfoList = client.queryInstalledChaincodes(peer); boolean found = false; for (ChaincodeInfo ccifo : ccinfoList) { - found = cc_name.equals(ccifo.getName()) && cc_path.equals(ccifo.getPath()) && cc_version.equals(ccifo.getVersion()); + found = ccName.equals(ccifo.getName()) && ccPath.equals(ccifo.getPath()) && ccVersion.equals(ccifo.getVersion()); if (found) { break; } @@ -595,14 +596,14 @@ private static boolean checkInstalledChaincode(HFClient client, Peer peer, Strin return found; } - private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String cc_name, String cc_path, String cc_version) throws InvalidArgumentException, ProposalException { - out("Checking instantiated chaincode: %s, at version: %s, on peer: %s", cc_name, cc_version, peer.getName()); + private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException { + out("Checking instantiated chaincode: %s, at version: %s, on peer: %s", ccName, ccVersion, peer.getName()); List ccinfoList = channel.queryInstantiatedChaincodes(peer); boolean found = false; for (ChaincodeInfo ccifo : ccinfoList) { - found = cc_name.equals(ccifo.getName()) && cc_path.equals(ccifo.getPath()) && cc_version.equals(ccifo.getVersion()); + found = ccName.equals(ccifo.getName()) && ccPath.equals(ccifo.getPath()) && ccVersion.equals(ccifo.getVersion()); if (found) { break; } diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java index a5166676..9cbeca02 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java @@ -578,7 +578,7 @@ private Channel constructChannel(String name, HFClient client, SampleOrg sampleO for (String peerName : sampleOrg.getPeerNames()) { String peerLocation = sampleOrg.getPeerLocation(peerName); - Properties peerProperties = testConfig.getPeerProperties(peerName);//test properties for peer.. if any. + Properties peerProperties = testConfig.getPeerProperties(peerName); //test properties for peer.. if any. if (peerProperties == null) { peerProperties = new Properties(); } diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleOrg.java b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleOrg.java index b390bc17..86b51d72 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/SampleOrg.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/SampleOrg.java @@ -18,7 +18,7 @@ * 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 + * 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. @@ -44,7 +44,7 @@ public class SampleOrg { Set peers = new HashSet<>(); private SampleUser admin; private String caLocation; - private Properties caProperties= null; + private Properties caProperties = null; private SampleUser peerAdmin; @@ -160,8 +160,8 @@ public void addPeer(Peer peer) { peers.add(peer); } - public void setCAProperties(Properties CAProperties) { - this.caProperties = CAProperties; + public void setCAProperties(Properties caProperties) { + this.caProperties = caProperties; } public Properties getCAProperties() { diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/Util.java b/src/test/java/org/hyperledger/fabric/sdkintegration/Util.java index 0c5ee87f..0fa352ba 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/Util.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/Util.java @@ -35,6 +35,11 @@ class Util { + /** + * Private constructor to prevent instantiation. + */ + private Util() { } + /** * Generate a targz inputstream from source folder. * @@ -43,22 +48,18 @@ class Util { * @return return inputstream. * @throws IOException */ - public static InputStream generateTarGzInputStream(File src, String pathPrefix) throws IOException { File sourceDirectory = src; - //File destinationArchive = new File(target); ByteArrayOutputStream bos = new ByteArrayOutputStream(500000); String sourcePath = sourceDirectory.getAbsolutePath(); - // FileOutputStream destinationOutputStream = new FileOutputStream(destinationArchive); TarArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(new BufferedOutputStream(bos))); archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); try { Collection childrenFiles = org.apache.commons.io.FileUtils.listFiles(sourceDirectory, null, true); - // childrenFiles.remove(destinationArchive); ArchiveEntry archiveEntry; FileInputStream fileInputStream; diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java index f9db609b..96ca29cc 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/AttributeTest.java @@ -4,7 +4,7 @@ * 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 + * 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. @@ -19,36 +19,36 @@ 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()); - } - } + 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 index 5f6075cc..e98bcd86 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/EnrollmentRequestTest.java @@ -4,7 +4,7 @@ * 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 + * 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. @@ -19,85 +19,85 @@ 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()); - } - } + 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 diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java index 0ae4db8f..733aaf75 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/RegistrationRequestTest.java @@ -4,7 +4,7 @@ * 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 + * 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. @@ -18,96 +18,96 @@ 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()); - } - } + 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 index b2250ed5..4e31ca51 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/RevocationRequestTest.java @@ -4,7 +4,7 @@ * 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 + * 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. @@ -18,106 +18,106 @@ 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()); - } - } + 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 diff --git a/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientEnrollIT.java b/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientEnrollIT.java index 05279ea4..533cc8d0 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientEnrollIT.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientEnrollIT.java @@ -2,7 +2,7 @@ * 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 + * 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. @@ -53,7 +53,7 @@ public class HFCAClientEnrollIT { private static final String TEST_USER3_PW = "user3pw"; private static final String TEST_USER1_ORG = "Org2"; private static final String TEST_USER1_AFFILIATION = "org1.department1"; - private static final String TEST_WITH_INTEGRATION_ORG= "peerOrg1"; + private static final String TEST_WITH_INTEGRATION_ORG = "peerOrg1"; private SampleStore sampleStore; private HFCAClient client; SampleUser admin;