Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 9992851

Browse files
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 <chrism@fast.au.fujitsu.com>
1 parent 2aee0bd commit 9992851

File tree

14 files changed

+434
-431
lines changed

14 files changed

+434
-431
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
<failsOnError>true</failsOnError>
311311
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
312312
<configLocation>checkstyle-config.xml</configLocation>
313+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
313314
</configuration>
314315
</plugin>
315316
<plugin>

src/test/fixture/sdkintegration/javacc/example_cc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ limitations under the License.
6565
</configuration>
6666
</execution>
6767
</executions>
68-
</plugin>
68+
</plugin>
6969
</plugins>
7070
</build>
7171
<dependencies>

src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -28,108 +28,108 @@
2828

2929
public class PeerClientTest {
3030

31-
// static Channel testChain = null;
32-
// static ChaincodeResponse deployResponse = null;
33-
// static ChaincodeResponse javaDeployResponse = null;
31+
// static Channel testChain = null;
32+
// static ChaincodeResponse deployResponse = null;
33+
// static ChaincodeResponse javaDeployResponse = null;
3434
//
35-
// @BeforeClass
36-
// public static void setupChain() {
37-
// testChain = new Channel("chain1");
38-
// try {
39-
// testChain.setMemberServicesUrl("grpc://localhost:7054", null);
40-
// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties"));
41-
// testChain.addPeer("grpc://localhost:7051", null);
42-
// //testChain.setDevMode(true);
43-
// SampleUser registrar = testChain.getUser("admin");
44-
// if (!registrar.isEnrolled()) {
45-
// registrar = testChain.enroll("admin", "Xurw3yU9zI0l");
46-
// }
47-
// testChain.setRegistrar(registrar);
48-
// deployResponse = deploy();
49-
// javaDeployResponse = deployJava();
50-
// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call
51-
// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) {
52-
// cex.printStackTrace();// TODO: Handle the exception properly
53-
// }
54-
// }
35+
// @BeforeClass
36+
// public static void setupChain() {
37+
// testChain = new Channel("chain1");
38+
// try {
39+
// testChain.setMemberServicesUrl("grpc://localhost:7054", null);
40+
// testChain.setKeyValStore(new SampleStore(System.getProperty("user.home")+"/test.properties"));
41+
// testChain.addPeer("grpc://localhost:7051", null);
42+
// //testChain.setDevMode(true);
43+
// SampleUser registrar = testChain.getUser("admin");
44+
// if (!registrar.isEnrolled()) {
45+
// registrar = testChain.enroll("admin", "Xurw3yU9zI0l");
46+
// }
47+
// testChain.setRegistrar(registrar);
48+
// deployResponse = deploy();
49+
// javaDeployResponse = deployJava();
50+
// TimeUnit.SECONDS.sleep(10);// deployment takes time, so wait for it to complete before making a query or invoke call
51+
// } catch(CertificateException | RegistrationException | EnrollmentException | InterruptedException cex) {
52+
// cex.printStackTrace();// TODO: Handle the exception properly
53+
// }
54+
// }
5555
//
5656
//
57-
// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException {
58-
// InstallProposalRequest request = new InstallProposalRequest();
59-
// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02");
60-
// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000")));
61-
// SampleUser user = getUser("User1", "bank_a");
62-
// request.setChaincodeName("mycc");
63-
// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG);
64-
// return user.deploy(request);
65-
// }
57+
// public static ChaincodeResponse deploy() throws RegistrationException, EnrollmentException, ProposalException {
58+
// InstallProposalRequest request = new InstallProposalRequest();
59+
// request.setChaincodePath("github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02");
60+
// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000")));
61+
// SampleUser user = getUser("User1", "bank_a");
62+
// request.setChaincodeName("mycc");
63+
// request.setChaincodeLanguage(ChaincodeLanguage.GO_LANG);
64+
// return user.deploy(request);
65+
// }
6666
//
67-
// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException {
68-
// InstallProposalRequest request = new InstallProposalRequest();
69-
// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example");
70-
// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000")));
71-
// SampleUser user = getUser("User1", "bank_a");
72-
// request.setChaincodeName("myccj");
73-
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
74-
// return user.deploy(request);
67+
// public static ChaincodeResponse deployJava() throws RegistrationException, EnrollmentException {
68+
// InstallProposalRequest request = new InstallProposalRequest();
69+
// request.setChaincodePath(System.getenv("GOPATH")+"/src/github.com/hyperledger/fabric/examples/chaincode/java/Example");
70+
// request.setArgs(new ArrayList<>(Arrays.asList("init", "a", "700", "b", "20000")));
71+
// SampleUser user = getUser("User1", "bank_a");
72+
// request.setChaincodeName("myccj");
73+
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
74+
// return user.deploy(request);
7575
//
76-
// }
76+
// }
7777
//
78-
// @Test
79-
// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException {
80-
// testInvoke(); // the amount is stored
81-
// QueryRequest request = new QueryRequest();
82-
// request.setArgs(new ArrayList<>(Arrays.asList("query", "a")));
83-
// request.setChaincodeID(deployResponse.getChaincodeID());
84-
// request.setChaincodeName(deployResponse.getChaincodeID());
85-
// SampleUser user = getUser("User1", "bank_a");
86-
// user.query(request);
87-
// }
78+
// @Test
79+
// public void testQuery() throws RegistrationException, EnrollmentException, ChaincodeException {
80+
// testInvoke(); // the amount is stored
81+
// QueryRequest request = new QueryRequest();
82+
// request.setArgs(new ArrayList<>(Arrays.asList("query", "a")));
83+
// request.setChaincodeID(deployResponse.getChaincodeID());
84+
// request.setChaincodeName(deployResponse.getChaincodeID());
85+
// SampleUser user = getUser("User1", "bank_a");
86+
// user.query(request);
87+
// }
8888
//
89-
// @Test
90-
// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException {
91-
// InvokeRequest request = new InvokeRequest();
92-
// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200")));
93-
// request.setChaincodeID(deployResponse.getChaincodeID());
94-
// request.setChaincodeName(deployResponse.getChaincodeID());
95-
// SampleUser user = getUser("User1", "bank_a");
96-
// user.invoke(request);
97-
// }
89+
// @Test
90+
// public void testInvoke() throws RegistrationException, EnrollmentException, ChaincodeException {
91+
// InvokeRequest request = new InvokeRequest();
92+
// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200")));
93+
// request.setChaincodeID(deployResponse.getChaincodeID());
94+
// request.setChaincodeName(deployResponse.getChaincodeID());
95+
// SampleUser user = getUser("User1", "bank_a");
96+
// user.invoke(request);
97+
// }
9898
//
99-
// @Test
100-
// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException {
101-
// testInvokeJava();
102-
// QueryRequest request = new QueryRequest();
103-
// request.setArgs(new ArrayList<>(Arrays.asList("query", "a")));
104-
// request.setChaincodeID(javaDeployResponse.getChaincodeID());
105-
// request.setChaincodeName(javaDeployResponse.getChaincodeID());
106-
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
107-
// SampleUser user = getUser("User1", "bank_a");
108-
// user.query(request);
109-
// }
99+
// @Test
100+
// public void testQueryJava() throws RegistrationException, EnrollmentException, ChaincodeException {
101+
// testInvokeJava();
102+
// QueryRequest request = new QueryRequest();
103+
// request.setArgs(new ArrayList<>(Arrays.asList("query", "a")));
104+
// request.setChaincodeID(javaDeployResponse.getChaincodeID());
105+
// request.setChaincodeName(javaDeployResponse.getChaincodeID());
106+
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
107+
// SampleUser user = getUser("User1", "bank_a");
108+
// user.query(request);
109+
// }
110110
//
111-
// @Test
112-
// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException {
113-
// InvokeRequest request = new InvokeRequest();
114-
// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200")));
115-
// request.setChaincodeID(javaDeployResponse.getChaincodeID());
116-
// request.setChaincodeName(javaDeployResponse.getChaincodeID());
117-
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
118-
// SampleUser user = getUser("User1", "bank_a");
119-
// user.invoke(request);
120-
// }
111+
// @Test
112+
// public void testInvokeJava() throws RegistrationException, EnrollmentException, ChaincodeException {
113+
// InvokeRequest request = new InvokeRequest();
114+
// request.setArgs(new ArrayList<>(Arrays.asList("invoke", "a", "b", "200")));
115+
// request.setChaincodeID(javaDeployResponse.getChaincodeID());
116+
// request.setChaincodeName(javaDeployResponse.getChaincodeID());
117+
// request.setChaincodeLanguage(ChaincodeLanguage.JAVA);
118+
// SampleUser user = getUser("User1", "bank_a");
119+
// user.invoke(request);
120+
// }
121121
//
122-
// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException {
123-
// SampleUser user = testChain.getUser(enrollmentId);
124-
// if (!user.isRegistered()) {
125-
// RegistrationRequest registrationRequest = new RegistrationRequest();
126-
// registrationRequest.setEnrollmentID(enrollmentId);
127-
// registrationRequest.setAffiliation(affiliation);
128-
// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest?
129-
// user = testChain.registerAndEnroll(registrationRequest);
130-
// } else if (!user.isEnrolled()) {
131-
// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret());
132-
// }
133-
// return user;
134-
// }
122+
// private static SampleUser getUser(String enrollmentId, String affiliation) throws RegistrationException, EnrollmentException {
123+
// SampleUser user = testChain.getUser(enrollmentId);
124+
// if (!user.isRegistered()) {
125+
// RegistrationRequest registrationRequest = new RegistrationRequest();
126+
// registrationRequest.setEnrollmentID(enrollmentId);
127+
// registrationRequest.setAffiliation(affiliation);
128+
// //registrationRequest.setAccount(); TODO setAccount missing from registrationRequest?
129+
// user = testChain.registerAndEnroll(registrationRequest);
130+
// } else if (!user.isEnrolled()) {
131+
// user = testChain.enroll(enrollmentId, user.getEnrollmentSecret());
132+
// }
133+
// return user;
134+
// }
135135
}

src/test/java/org/hyperledger/fabric/sdk/security/CryptoPrimitivesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void testAddCACertificateToTrustStoreNoCert() throws InvalidArgumentExcep
272272

273273
@Test(expected = InvalidArgumentException.class)
274274
public void testAddCACertsNullInput() throws Exception {
275-
crypto.addCACertificateToTrustStore((File)null, null);;
275+
crypto.addCACertificateToTrustStore((File) null, null);
276276
}
277277

278278
@Test(expected = CryptoException.class)
@@ -368,7 +368,7 @@ public void testValidateNotSignedCertificate() {
368368
}
369369

370370
@Test
371-
public void testValidateInvalidCertificate() throws IOException, CertificateException{
371+
public void testValidateInvalidCertificate() throws IOException, CertificateException {
372372
BufferedInputStream pem = new BufferedInputStream(new ByteArrayInputStream(invalidPemCert));
373373

374374
assertFalse(crypto.validateCertificate(invalidPemCert));
@@ -481,7 +481,7 @@ public void testSign() {
481481

482482

483483
@Test
484-
public void testKeyGen() throws CryptoException{
484+
public void testKeyGen() throws CryptoException {
485485
Assert.assertNotNull(crypto.keyGen());
486486
Assert.assertSame(KeyPair.class, crypto.keyGen().getClass());
487487
}

src/test/java/org/hyperledger/fabric/sdk/testutils/TestConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public class TestConfig {
6464
private static final String INTEGRATIONTESTSTLS = PROPBASE + "integrationtests.tls";
6565

6666
private static TestConfig config;
67-
private final static Properties sdkProperties = new Properties();
67+
private static final Properties sdkProperties = new Properties();
6868
private final boolean runningTLS;
6969
private final boolean runningFabricCATLS;
7070
private final boolean runningFabricTLS;
71-
private final static HashMap<String, SampleOrg> sampleOrgs = new HashMap<>();
71+
private static final HashMap<String, SampleOrg> sampleOrgs = new HashMap<>();
7272

7373
private TestConfig() {
7474
File loadFile;

src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import java.io.File;
1818
import java.net.MalformedURLException;
1919
import java.util.Collection;
20-
import java.util.Hashtable;
2120
import java.util.LinkedList;
2221
import java.util.List;
23-
import java.util.Optional;
2422
import java.util.Set;
2523
import java.util.concurrent.CompletableFuture;
2624
import java.util.concurrent.CompletionException;
@@ -177,6 +175,9 @@ public void setup() {
177175
}
178176
}
179177

178+
// Disable MethodLength as this method is for instructional purposes and hence
179+
// we don't want to split it into smaller pieces
180+
// CHECKSTYLE:OFF: MethodLength
180181
void runChannel(HFClient client, Channel channel, SampleOrg sampleOrg, final int delta) {
181182
final String channelName = channel.getName();
182183
try {
@@ -272,7 +273,7 @@ void runChannel(HFClient client, Channel channel, SampleOrg sampleOrg, final int
272273
upgradeProposalRequest.setChaincodeID(chaincodeID_11);
273274
upgradeProposalRequest.setProposalWaitTime(testConfig.getProposalWaitTime());
274275
upgradeProposalRequest.setFcn("init");
275-
upgradeProposalRequest.setArgs(new String[] {});// no arguments don't change the ledger see chaincode.
276+
upgradeProposalRequest.setArgs(new String[] {}); // no arguments don't change the ledger see chaincode.
276277

277278
ChaincodeEndorsementPolicy chaincodeEndorsementPolicy;
278279

@@ -576,16 +577,16 @@ private void waitOnFabric(int additional) {
576577
// }
577578
}
578579

579-
private static boolean checkInstalledChaincode(HFClient client, Peer peer, String cc_name, String cc_path, String cc_version) throws InvalidArgumentException, ProposalException {
580+
private static boolean checkInstalledChaincode(HFClient client, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException {
580581

581-
out("Checking installed chaincode: %s, at version: %s, on peer: %s", cc_name, cc_version, peer.getName());
582+
out("Checking installed chaincode: %s, at version: %s, on peer: %s", ccName, ccVersion, peer.getName());
582583
List<ChaincodeInfo> ccinfoList = client.queryInstalledChaincodes(peer);
583584

584585
boolean found = false;
585586

586587
for (ChaincodeInfo ccifo : ccinfoList) {
587588

588-
found = cc_name.equals(ccifo.getName()) && cc_path.equals(ccifo.getPath()) && cc_version.equals(ccifo.getVersion());
589+
found = ccName.equals(ccifo.getName()) && ccPath.equals(ccifo.getPath()) && ccVersion.equals(ccifo.getVersion());
589590
if (found) {
590591
break;
591592
}
@@ -595,14 +596,14 @@ private static boolean checkInstalledChaincode(HFClient client, Peer peer, Strin
595596
return found;
596597
}
597598

598-
private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String cc_name, String cc_path, String cc_version) throws InvalidArgumentException, ProposalException {
599-
out("Checking instantiated chaincode: %s, at version: %s, on peer: %s", cc_name, cc_version, peer.getName());
599+
private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException {
600+
out("Checking instantiated chaincode: %s, at version: %s, on peer: %s", ccName, ccVersion, peer.getName());
600601
List<ChaincodeInfo> ccinfoList = channel.queryInstantiatedChaincodes(peer);
601602

602603
boolean found = false;
603604

604605
for (ChaincodeInfo ccifo : ccinfoList) {
605-
found = cc_name.equals(ccifo.getName()) && cc_path.equals(ccifo.getPath()) && cc_version.equals(ccifo.getVersion());
606+
found = ccName.equals(ccifo.getName()) && ccPath.equals(ccifo.getPath()) && ccVersion.equals(ccifo.getVersion());
606607
if (found) {
607608
break;
608609
}

src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private Channel constructChannel(String name, HFClient client, SampleOrg sampleO
578578
for (String peerName : sampleOrg.getPeerNames()) {
579579
String peerLocation = sampleOrg.getPeerLocation(peerName);
580580

581-
Properties peerProperties = testConfig.getPeerProperties(peerName);//test properties for peer.. if any.
581+
Properties peerProperties = testConfig.getPeerProperties(peerName); //test properties for peer.. if any.
582582
if (peerProperties == null) {
583583
peerProperties = new Properties();
584584
}

src/test/java/org/hyperledger/fabric/sdkintegration/SampleOrg.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Licensed under the Apache License, Version 2.0 (the "License");
1919
* you may not use this file except in compliance with the License.
2020
* You may obtain a copy of the License at
21-
* http://www.apache.org/licenses/LICENSE-2.0
21+
* http://www.apache.org/licenses/LICENSE-2.0
2222
* Unless required by applicable law or agreed to in writing, software
2323
* distributed under the License is distributed on an "AS IS" BASIS,
2424
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,7 +44,7 @@ public class SampleOrg {
4444
Set<Peer> peers = new HashSet<>();
4545
private SampleUser admin;
4646
private String caLocation;
47-
private Properties caProperties= null;
47+
private Properties caProperties = null;
4848

4949
private SampleUser peerAdmin;
5050

@@ -160,8 +160,8 @@ public void addPeer(Peer peer) {
160160
peers.add(peer);
161161
}
162162

163-
public void setCAProperties(Properties CAProperties) {
164-
this.caProperties = CAProperties;
163+
public void setCAProperties(Properties caProperties) {
164+
this.caProperties = caProperties;
165165
}
166166

167167
public Properties getCAProperties() {

0 commit comments

Comments
 (0)