Skip to content

Commit

Permalink
FAB-4536 Enable checkstyle for test suite
Browse files Browse the repository at this point in the history
. 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>
  • Loading branch information
chrism28282828 committed Jun 12, 2017
1 parent 2aee0bd commit 9992851
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 431 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
<failsOnError>true</failsOnError>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<configLocation>checkstyle-config.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/test/fixture/sdkintegration/javacc/example_cc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ limitations under the License.
</configuration>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
188 changes: 94 additions & 94 deletions src/test/java/org/hyperledger/fabric/sdk/PeerClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, SampleOrg> sampleOrgs = new HashMap<>();
private static final HashMap<String, SampleOrg> sampleOrgs = new HashMap<>();

private TestConfig() {
File loadFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<ChaincodeInfo> 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;
}
Expand All @@ -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<ChaincodeInfo> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -44,7 +44,7 @@ public class SampleOrg {
Set<Peer> peers = new HashSet<>();
private SampleUser admin;
private String caLocation;
private Properties caProperties= null;
private Properties caProperties = null;

private SampleUser peerAdmin;

Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 9992851

Please sign in to comment.