diff --git a/checkstyle-config.xml b/checkstyle-config.xml index 887d5de4..42258c8f 100644 --- a/checkstyle-config.xml +++ b/checkstyle-config.xml @@ -52,20 +52,23 @@ - - - - - - + + + + + - - + + + + + + @@ -90,12 +93,8 @@ - - - - - - + + @@ -122,6 +121,7 @@ + diff --git a/pom.xml b/pom.xml index a8ef1013..b6b0d634 100644 --- a/pom.xml +++ b/pom.xml @@ -28,46 +28,20 @@ http://github.com/hyperledger/fabric-sdk-java - 1.56.0 + 1.57.1 3.22.5 - 1.74 + 1.76 4.5.14 - 3.4.1 + 3.5.0 true UTF-8 0.8.10 2.20.0 IntegrationSuite.java gpg + 8 - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.0.0 - - - - checkstyle - - - - - suppressions.xml - checkstyle.suppressions.file - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - - @@ -80,14 +54,14 @@ io.opentelemetry opentelemetry-bom - 1.27.0 + 1.28.0 pom import io.opentelemetry.instrumentation opentelemetry-instrumentation-bom-alpha - 1.27.0-alpha + 1.28.0-alpha pom import @@ -119,10 +93,11 @@ io.grpc grpc-stub - - org.apache.tomcat - annotations-api - 6.0.53 + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 provided @@ -199,24 +174,21 @@ com.google.api api-common - 2.12.0 + 2.15.0 - org.glassfish javax.json 1.1.4 - org.yaml snakeyaml 2.0 - org.miracl.milagro.amcl milagro-crypto-java @@ -230,13 +202,6 @@ 2.3.1 - - - javax.annotation - javax.annotation-api - 1.3.2 - - io.opentelemetry opentelemetry-api @@ -297,7 +262,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M7 + 3.1.2 ${surefireArgLine} @@ -356,10 +321,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.11.0 - 1.8 - 1.8 + ${javaVersion} + ${javaVersion} true true @@ -427,33 +392,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.0.0 - - - compile - compile - - check - - - - - true - true - true - true - - - ${project.build.sourceDirectory} - - - checkstyle-config.xml - true - - org.jacoco jacoco-maven-plugin @@ -589,15 +527,15 @@ org.apache.maven.plugins maven-antrun-plugin - 1.8 + 3.1.0 generate-test-resources - + - + run @@ -640,7 +578,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources @@ -718,13 +656,66 @@ --no-module-directories + + maven-compiler-release + + [9,) + + + ${javaVersion} + + + + checkstyle + + [11,) + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.0 + + + validate + validate + + check + + + + + true + true + true + true + checkstyle-config.xml + true + + + ${project.build.sourceDirectory} + ${project.build.testSourceDirectory} + + + + + com.puppycrawl.tools + checkstyle + 10.12.2 + + + + + + release maven-assembly-plugin - 3.4.2 + 3.6.0 jar-with-dependencies @@ -742,7 +733,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts diff --git a/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java b/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java index 03745be5..486b5238 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java +++ b/src/main/java/org/hyperledger/fabric/sdk/BlockEvent.java @@ -13,19 +13,18 @@ */ package org.hyperledger.fabric.sdk; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import com.google.protobuf.InvalidProtocolBufferException; -import org.hyperledger.fabric.protos.common.Common.Block; import org.hyperledger.fabric.protos.peer.EventsPackage; import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + /** * A wrapper for the Block returned in an Event * - * @see Block + * @see org.hyperledger.fabric.protos.common.Common.Block */ public class BlockEvent extends BlockInfo { private final Peer peer; diff --git a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java index aab235a9..108eb1a4 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java +++ b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java @@ -156,7 +156,7 @@ private void setDefaultProperties(Properties props) { props.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] {20L, TimeUnit.SECONDS}); } if (!props.containsKey("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls")) { - props.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {true}); + props.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {true}); } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgProposalResponse.java index 748712d8..6b6a5a81 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgProposalResponse.java @@ -8,13 +8,11 @@ package org.hyperledger.fabric.sdk; -import java.util.Collection; - import org.hyperledger.fabric.sdk.transaction.TransactionContext; /** * Result of sending a {@link LifecycleApproveChaincodeDefinitionForMyOrgRequest}. - * Also see {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, Collection)} + * Also see {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, java.util.Collection)} *

* Does not return any request specific results. */ diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java index 04ecfac4..d3531de3 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleApproveChaincodeDefinitionForMyOrgRequest.java @@ -8,8 +8,6 @@ package org.hyperledger.fabric.sdk; -import java.util.Collection; - import com.google.protobuf.ByteString; import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; import org.hyperledger.fabric.sdk.helper.Config; @@ -17,7 +15,7 @@ /** * LifecycleApproveChaincodeDefinitionForMyOrgRequest parameters for approving chaincode with lifecycle. - * Send to peers with {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, Collection)} + * Send to peers with {@link Channel#sendLifecycleApproveChaincodeDefinitionForMyOrgProposal(LifecycleApproveChaincodeDefinitionForMyOrgRequest, java.util.Collection)} */ public class LifecycleApproveChaincodeDefinitionForMyOrgRequest extends LifecycleRequest { private static final Config config = Config.getConfig(); diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java index ddf13785..bc3ac3c1 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleChaincodeEndorsementPolicy.java @@ -8,18 +8,6 @@ package org.hyperledger.fabric.sdk; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import com.google.protobuf.ByteString; import io.grpc.netty.shaded.io.netty.util.internal.StringUtil; import org.apache.commons.io.IOUtils; @@ -33,6 +21,17 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import static java.lang.String.format; /** diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleCommitChaincodeDefinitionProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleCommitChaincodeDefinitionProposalResponse.java index f0f9adce..547a96c9 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleCommitChaincodeDefinitionProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleCommitChaincodeDefinitionProposalResponse.java @@ -8,13 +8,11 @@ package org.hyperledger.fabric.sdk; -import java.util.Collection; - import org.hyperledger.fabric.sdk.transaction.TransactionContext; /** * Response to a {@link LifecycleCommitChaincodeDefinitionRequest} - * Also see {@link Channel#sendLifecycleCommitChaincodeDefinitionProposal(LifecycleCommitChaincodeDefinitionRequest, Collection)}} + * Also see {@link Channel#sendLifecycleCommitChaincodeDefinitionProposal(LifecycleCommitChaincodeDefinitionRequest, java.util.Collection)}} *

* Response does not return any request specific parameters. */ diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeRequest.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeRequest.java index 718d9ce5..17fa0cc6 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleInstallChaincodeRequest.java @@ -8,13 +8,11 @@ package org.hyperledger.fabric.sdk; -import java.util.Collection; - import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; /** * LifecycleInstallChaincodeRequest parameters for installing chaincode with lifecycle - * see also {@link HFClient#sendLifecycleInstallChaincodeRequest(LifecycleInstallChaincodeRequest, Collection)} + * see also {@link HFClient#sendLifecycleInstallChaincodeRequest(LifecycleInstallChaincodeRequest, java.util.Collection)} */ public class LifecycleInstallChaincodeRequest extends LifecycleRequest { diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionsRequest.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionsRequest.java index 2a6d7db7..a90e1514 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionsRequest.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryChaincodeDefinitionsRequest.java @@ -8,11 +8,9 @@ package org.hyperledger.fabric.sdk; -import java.util.Collection; - /** * Request for definitions of commited chaincode. - * See also {@link Channel#lifecycleQueryChaincodeDefinitions(LifecycleQueryChaincodeDefinitionsRequest, Collection)} + * See also {@link Channel#lifecycleQueryChaincodeDefinitions(LifecycleQueryChaincodeDefinitionsRequest, java.util.Collection)} */ public final class LifecycleQueryChaincodeDefinitionsRequest extends LifecycleRequest { LifecycleQueryChaincodeDefinitionsRequest(User userContext) { diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java index cbf7498c..49f5303a 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodeProposalResponse.java @@ -8,8 +8,6 @@ package org.hyperledger.fabric.sdk; -import java.nio.file.Path; - import com.google.protobuf.ByteString; import org.hyperledger.fabric.protos.peer.ProposalResponsePackage; import org.hyperledger.fabric.protos.peer.lifecycle.Lifecycle; @@ -72,7 +70,7 @@ public String getPackageId() throws ProposalException { } /** - * The lable used by this chaincode. This is defined by the installed chaincode. See label parameter in {@link LifecycleChaincodePackage#fromSource(String, Path, TransactionRequest.Type, String, Path)} + * The lable used by this chaincode. This is defined by the installed chaincode. See label parameter in {@link LifecycleChaincodePackage#fromSource(String, java.nio.file.Path, TransactionRequest.Type, String, java.nio.file.Path)} * @return the label * @throws ProposalException */ diff --git a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodesProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodesProposalResponse.java index 9143ceec..0921f7c4 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodesProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/LifecycleQueryInstalledChaincodesProposalResponse.java @@ -8,7 +8,6 @@ package org.hyperledger.fabric.sdk; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -75,7 +74,7 @@ public class LifecycleQueryInstalledChaincodesResult { } /** - * The label used by this chaincode. This is defined by the installed chaincode. See label parameter in {@link LifecycleChaincodePackage#fromSource(String, Path, TransactionRequest.Type, String, Path)} + * The label used by this chaincode. This is defined by the installed chaincode. See label parameter in {@link LifecycleChaincodePackage#fromSource(String, java.nio.file.Path, TransactionRequest.Type, String, java.nio.file.Path)} * * @return Label */ diff --git a/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java b/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java index c8a5599d..fdc886e7 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java +++ b/src/main/java/org/hyperledger/fabric/sdk/helper/Config.java @@ -213,7 +213,6 @@ private Config() { org.apache.log4j.Level setTo; switch (inLogLevel.toUpperCase()) { - case "TRACE": setTo = org.apache.log4j.Level.TRACE; break; @@ -237,22 +236,18 @@ private Config() { default: setTo = Level.INFO; break; - } if (null != setTo) { org.apache.log4j.Logger.getLogger("org.hyperledger.fabric").setLevel(setTo); } - } openTelemetry = AutoConfiguredOpenTelemetrySdk - .builder() - .setResultAsGlobal(false) - .build() - .getOpenTelemetrySdk(); + .builder() + .build() + .getOpenTelemetrySdk(); } - } /** @@ -265,7 +260,6 @@ public static Config getConfig() { config = new Config(); } return config; - } /** diff --git a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuiteFactory.java b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuiteFactory.java index b56c4c37..b3fed1e2 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuiteFactory.java +++ b/src/main/java/org/hyperledger/fabric/sdk/security/CryptoSuiteFactory.java @@ -21,7 +21,6 @@ import org.hyperledger.fabric.sdk.exception.CryptoException; import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; -import org.hyperledger.fabric.sdk.helper.Config; /** * Factory to produce a set of crypto suite implementations offering differing cryptographic algorithms and strengths. @@ -60,7 +59,7 @@ public interface CryptoSuiteFactory { /** * This will return the default Crypto Suite Factory implementation. * Can be overwritten by org.hyperledger.fabric.sdk.crypto.default_crypto_suite_factory property. - * see {@link Config#getDefaultCryptoSuiteFactory()} + * see {@link org.hyperledger.fabric.sdk.helper.Config#getDefaultCryptoSuiteFactory()} * Classes specified by this property must implement a public static method instance that * returns back a single instance of this factory. * diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java index 61d41d6c..8a4987cd 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAAffiliation.java @@ -387,7 +387,7 @@ public HFCAAffiliationResp delete(User registrar, boolean force) throws Affiliat AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); throw affiliationException; - } catch (Exception e) { + } catch (Exception e) { String msg = format("Error while deleting affiliation %s url: %s %s ", this.name, deleteURL, e.getMessage()); AffiliationException affiliationException = new AffiliationException(msg, e); logger.error(msg); diff --git a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java index f5c495a0..34637c27 100644 --- a/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java +++ b/src/main/java/org/hyperledger/fabric_ca/sdk/HFCAClient.java @@ -14,55 +14,6 @@ package org.hyperledger.fabric_ca.sdk; -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.Socket; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.security.KeyFactory; -import java.security.KeyManagementException; -import java.security.KeyPair; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.X509EncodedKeySpec; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonReader; -import javax.json.JsonValue; -import javax.json.JsonWriter; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import javax.xml.bind.DatatypeConverter; - import com.google.protobuf.InvalidProtocolBufferException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -129,6 +80,52 @@ import org.hyperledger.fabric_ca.sdk.helper.Config; import org.hyperledger.fabric_ca.sdk.helper.Util; +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonReader; +import javax.json.JsonValue; +import javax.json.JsonWriter; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.xml.bind.DatatypeConverter; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.KeyFactory; +import java.security.KeyManagementException; +import java.security.KeyPair; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PublicKey; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Collection; +import java.util.Date; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; + import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java b/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java index ad99f461..faf1d598 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/ChannelTest.java @@ -14,27 +14,6 @@ package org.hyperledger.fabric.sdk; -//Allow throwing undeclared checked execeptions in mock code. -//CHECKSTYLE.OFF: IllegalImport - -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - import com.google.protobuf.ByteString; import io.grpc.Status; import io.grpc.StatusRuntimeException; @@ -57,7 +36,24 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import sun.misc.Unsafe; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; import static org.hyperledger.fabric.sdk.Channel.PeerOptions.createPeerOptions; import static org.hyperledger.fabric.sdk.testutils.TestUtils.assertArrayListEquals; @@ -71,8 +67,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -//CHECKSTYLE.ON: IllegalImport - public class ChannelTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -882,10 +876,7 @@ public void testQueryInstalledChaincodesERROR() throws Exception { final Channel channel = createRunningChannel(null); Peer peer = channel.getPeers().iterator().next(); - final CompletableFuture settableFuture = new CompletableFuture<>(); - // settableFuture.setException(new Error("Error bad bad bad")); - settableFuture.completeExceptionally(new Error("Error bad bad bad")); - setField(peer, "endorserClent", new MockEndorserClient(settableFuture)); + setField(peer, "endorserClent", new MockEndorserClient(new Error("Error bad bad bad"))); hfclient.queryChannels(peer); } @@ -898,10 +889,7 @@ public void testQueryInstalledChaincodesStatusRuntimeException() throws Exceptio final Channel channel = createRunningChannel(null); Peer peer = channel.getPeers().iterator().next(); - final CompletableFuture settableFuture = new CompletableFuture<>(); - settableFuture.completeExceptionally(new StatusRuntimeException(Status.ABORTED)); - - setField(peer, "endorserClent", new MockEndorserClient(settableFuture)); + setField(peer, "endorserClent", new MockEndorserClient(new StatusRuntimeException(Status.ABORTED))); hfclient.queryChannels(peer); } @@ -1173,30 +1161,18 @@ public void testRegisterBlockListenerShutdown2() throws Exception { channel.registerBlockListener(new LinkedBlockingQueue<>()); } - class MockEndorserClient extends EndorserClient { - final Throwable throwThis; + private static class MockEndorserClient extends EndorserClient { private final CompletableFuture returnedFuture; MockEndorserClient(Throwable throwThis) { super("blahchannlname", "blahpeerName", "blahURL", new Endpoint("grpc://loclhost:99", null).getChannelBuilder()); - if (throwThis == null) { - throw new IllegalArgumentException("Can't throw a null!"); - } - this.throwThis = throwThis; - this.returnedFuture = null; - } - - MockEndorserClient(CompletableFuture returnedFuture) { - super("blahchannlname", "blahpeerName", "blahURL", new Endpoint("grpc://loclhost:99", null).getChannelBuilder()); - this.throwThis = null; - this.returnedFuture = returnedFuture; + Objects.requireNonNull(throwThis); + returnedFuture = new CompletableFuture<>(); + returnedFuture.completeExceptionally(throwThis); } @Override public CompletableFuture sendProposalAsync(ProposalPackage.SignedProposal proposal) { - if (throwThis != null) { - getUnsafe().throwException(throwThis); - } return returnedFuture; } @@ -1204,16 +1180,5 @@ public CompletableFuture sendProposalA public boolean isChannelActive() { return true; } - - private Unsafe getUnsafe() { //lets us throw undeclared exceptions. - try { - Field field = Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - return (Unsafe) field.get(null); - } catch (Exception e) { - throw new RuntimeException(e); - } - } } - } diff --git a/src/test/java/org/hyperledger/fabric/sdk/NetworkConfigTest.java b/src/test/java/org/hyperledger/fabric/sdk/NetworkConfigTest.java index 95f1c62a..7bd0e688 100755 --- a/src/test/java/org/hyperledger/fabric/sdk/NetworkConfigTest.java +++ b/src/test/java/org/hyperledger/fabric/sdk/NetworkConfigTest.java @@ -47,7 +47,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class NetworkConfigTest { diff --git a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestUtils.java b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestUtils.java index c7deded4..735140d0 100644 --- a/src/test/java/org/hyperledger/fabric/sdk/testutils/TestUtils.java +++ b/src/test/java/org/hyperledger/fabric/sdk/testutils/TestUtils.java @@ -16,28 +16,10 @@ package org.hyperledger.fabric.sdk.testutils; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.PrivateKey; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.zip.GZIPInputStream; - import com.google.protobuf.ByteString; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.bouncycastle.openssl.PEMWriter; +import org.bouncycastle.openssl.jcajce.JcaPEMWriter; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -56,13 +38,28 @@ import org.hyperledger.fabric.sdk.security.CryptoSuite; import org.junit.Assert; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.PrivateKey; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.zip.GZIPInputStream; + import static java.lang.String.format; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -//import org.hyperledger.fabric.sdk.MockUser; -//import org.hyperledger.fabric.sdk.ClientTest.MockEnrollment; - public class TestUtils { private TestUtils() { @@ -489,12 +486,10 @@ public Identities.SerializedIdentity createSerializedIdentity() { public static String getPEMStringFromPrivateKey(PrivateKey privateKey) throws IOException { StringWriter pemStrWriter = new StringWriter(); - PEMWriter pemWriter = new PEMWriter(pemStrWriter); - - pemWriter.writeObject(privateKey); - - pemWriter.close(); - + try (JcaPEMWriter pemWriter = new JcaPEMWriter(pemStrWriter)) { + pemWriter.writeObject(privateKey); + pemWriter.flush(); + } return pemStrWriter.toString(); } diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java index df11b83f..fe3789a1 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endAndBackAgainIT.java @@ -296,7 +296,6 @@ public void runFabricTest(final SampleStore sampleStore) throws Exception { // 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 { diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java index 4eb998a4..4268e1f4 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java @@ -319,7 +319,7 @@ sampleOrgDomainName, format("/users/Admin@%s/msp/keystore", sampleOrgDomainName) Map expectedMoveRCMap = new HashMap<>(); // map from channel name to move chaincode's return code. - //CHECKSTYLE.OFF: Method length is 320 lines (max allowed is 150). + // checkstyle:ignore-next-line:MethodLength void runChannel(HFClient client, Channel channel, boolean installChaincode, SampleOrg sampleOrg, int delta) { class ChaincodeEventCapture { //A test class to capture chaincode events diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endLifecycleIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endLifecycleIT.java index cc81f786..86aa3180 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endLifecycleIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endLifecycleIT.java @@ -391,7 +391,7 @@ public void runFabricTest() throws Exception { out("That's all folks!"); } - //CHECKSTYLE.OFF: ParameterNumber + // checkstyle:ignore-next-line:ParameterNumber void runChannel(HFClient org1Client, Channel org1Channel, SampleOrg org1, Collection org1MyPeers, Collection org1OtherPeers, HFClient org2Client, Channel org2Channel, SampleOrg org2, Collection org2MyPeers, Collection org2OtherPeers, LifecycleChaincodePackage lifecycleChaincodePackage, String chaincodeName, @@ -618,6 +618,7 @@ private String lifecycleInstallChaincode(HFClient client, Collection peers } + // checkstyle:ignore-next-line:ParameterNumber CompletableFuture lifecycleApproveChaincodeDefinitionForMyOrg(HFClient client, Channel channel, Collection peers, long sequence, String chaincodeName, String chaincodeVersion, LifecycleChaincodeEndorsementPolicy chaincodeEndorsementPolicy, ChaincodeCollectionConfiguration chaincodeCollectionConfiguration, boolean initRequired, String org1ChaincodePackageID) throws InvalidArgumentException, ProposalException { @@ -654,6 +655,7 @@ CompletableFuture lifecycleApproveChaincodeDefinitionForMyOrg( } + // checkstyle:ignore-next-line:ParameterNumber private CompletableFuture commitChaincodeDefinitionRequest(HFClient client, Channel channel, long definitionSequence, String chaincodeName, String chaincodeVersion, LifecycleChaincodeEndorsementPolicy chaincodeEndorsementPolicy, ChaincodeCollectionConfiguration chaincodeCollectionConfiguration, @@ -687,6 +689,7 @@ private CompletableFuture commitChaincodeDefinitionRequest(HFC // Lifecycle Queries to used to verify code... + // checkstyle:ignore-next-line:ParameterNumber private void verifyByCheckCommitReadinessStatus(HFClient client, Channel channel, long definitionSequence, String chaincodeName, String chaincodeVersion, LifecycleChaincodeEndorsementPolicy chaincodeEndorsementPolicy, ChaincodeCollectionConfiguration chaincodeCollectionConfiguration, boolean initRequired, Collection org1MyPeers, diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endMTIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endMTIT.java index 7fa8e278..d818e63a 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endMTIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endMTIT.java @@ -153,16 +153,7 @@ static void out(String format, Object... args) { e.printStackTrace(); throw new RuntimeException(e); } - -// System.err.flush(); -// System.out.flush(); -// -// System.out.println(Thread.currentThread().getName() + ": " + format(format, args)); -// System.err.flush(); -// System.out.flush(); - } - //CHECKSTYLE.ON: Method length is 320 lines (max allowed is 150). static String printableString(final String string) { int maxLogStringLength = 64; diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/PrivateDataIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/PrivateDataIT.java index 7c9122ed..d215965e 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/PrivateDataIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/PrivateDataIT.java @@ -233,7 +233,6 @@ public void runFabricTest(final SampleStore sampleStore) throws Exception { // 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(); @@ -642,7 +641,7 @@ private void testPeerServiceEventingReplay(HFClient client, Channel replayTestCh assertEquals(envelopeInfo.getValidationCode(), 0); ++transactionEventCounts; - for (BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo ta : transactionEnvelopeInfo.getTransactionActionInfos()) { + for (BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo ta : transactionEnvelopeInfo.getTransactionActionInfos()) { ChaincodeEvent event = ta.getEvent(); if (event != null) { assertNotNull(event.getChaincodeId()); diff --git a/src/test/java/org/hyperledger/fabric_ca/sdk/HFCAClientTest.java b/src/test/java/org/hyperledger/fabric_ca/sdk/HFCAClientTest.java index f7cf4191..0344c227 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdk/HFCAClientTest.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdk/HFCAClientTest.java @@ -14,23 +14,6 @@ package org.hyperledger.fabric_ca.sdk; -import java.io.File; -import java.math.BigInteger; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.security.Key; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.KeyStore; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; - import org.hyperledger.fabric.sdk.Enrollment; import org.hyperledger.fabric.sdk.NetworkConfig; import org.hyperledger.fabric.sdk.exception.CryptoException; @@ -53,11 +36,27 @@ import org.junit.Test; import org.junit.rules.ExpectedException; +import java.io.File; +import java.math.BigInteger; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.Key; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + import static java.lang.String.format; import static org.hyperledger.fabric.sdk.testutils.TestUtils.invokeMethod; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class HFCAClientTest { diff --git a/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientIT.java b/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientIT.java index 0276300d..109039f9 100644 --- a/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientIT.java +++ b/src/test/java/org/hyperledger/fabric_ca/sdkintegration/HFCAClientIT.java @@ -12,28 +12,6 @@ package org.hyperledger.fabric_ca.sdkintegration; -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.StringReader; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.CertificateParsingException; -import java.security.cert.X509Certificate; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.xml.bind.DatatypeConverter; - import org.bouncycastle.asn1.ASN1OctetString; import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; import org.bouncycastle.asn1.x509.Extension; @@ -72,6 +50,26 @@ import org.junit.Test; import org.junit.rules.ExpectedException; +import javax.xml.bind.DatatypeConverter; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.StringReader; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateParsingException; +import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hyperledger.fabric.sdk.testutils.TestUtils.resetConfig;