1818import java .io .IOException ;
1919import java .net .MalformedURLException ;
2020import java .nio .file .Paths ;
21- import java .util .Arrays ;
2221import java .util .Collection ;
22+ import java .util .Collections ;
2323import java .util .EnumSet ;
2424import java .util .HashMap ;
2525import java .util .LinkedList ;
7878import static org .hyperledger .fabric .sdk .testutils .TestUtils .getPEMStringFromPrivateKey ;
7979import static org .hyperledger .fabric .sdk .testutils .TestUtils .resetConfig ;
8080import static org .hyperledger .fabric .sdk .testutils .TestUtils .testRemovingAddingPeersOrderers ;
81+ import static org .junit .Assert .assertArrayEquals ;
8182import static org .junit .Assert .assertEquals ;
8283import static org .junit .Assert .assertFalse ;
8384import static org .junit .Assert .assertNotNull ;
@@ -217,7 +218,7 @@ public void runFabricTest(final SampleStore sampleStore) throws Exception {
217218 sampleOrg = testConfig .getIntegrationTestsSampleOrg ("peerOrg2" );
218219 Channel barChannel = constructChannel (BAR_CHANNEL_NAME , client , sampleOrg );
219220 assertTrue (barChannel .isInitialized ());
220- /**
221+ /*
221222 * sampleStore.saveChannel uses {@link Channel#serializeChannel()}
222223 */
223224 sampleStore .saveChannel (barChannel );
@@ -345,7 +346,7 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
345346 boolean isFooChain = FOO_CHANNEL_NAME .equals (channelName );
346347 out ("Running channel %s" , channelName );
347348
348- Collection < Orderer > orderers = channel .getOrderers ();
349+ channel .getOrderers ();
349350 final ChaincodeID chaincodeID ;
350351 Collection <ProposalResponse > responses ;
351352 Collection <ProposalResponse > successful = new LinkedList <>();
@@ -381,15 +382,15 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
381382 /////////////////////////////////////////////////////////////////////////////////////////////////
382383 /////////////////////////////////////////////////////////////////////////////////////////////////
383384 /////////////////////////////////////////////////////////////////////////////////////////////////
384- /**
385+ /*
385386 * PLEASE READ !!
386387 *
387388 * The following is using Fabric v1.0 APIs for testing and demoing backward compatibility.
388389 * After v2.0 Fabric release unless there is a need for this in your application it is highly
389390 * encouraged to move to Fabric v2.0 capabilities and use the new v2.0 Lifecycle APIs for managing chaincode.
390391 * @see <a href="https://github.com/hyperledger/fabric-sdk-java/blob/master/docs/release_v2.0.0_notes.md#fabj-288-lifecycle-chaincode-management"</a>
391392 *
392- ** /
393+ */
393394 /////////////////////////////////////////////////////////////////////////////////////////////////
394395 /////////////////////////////////////////////////////////////////////////////////////////////////
395396 /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -496,7 +497,7 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
496497 instantiateProposalRequest .setChaincodeID (chaincodeID );
497498 instantiateProposalRequest .setChaincodeLanguage (CHAIN_CODE_LANG );
498499 instantiateProposalRequest .setFcn ("init" );
499- instantiateProposalRequest .setArgs (new String [] { "a" , "500" , "b" , "" + (200 + delta )} );
500+ instantiateProposalRequest .setArgs ("a" , "500" , "b" , String . valueOf (200 + delta ));
500501 Map <String , byte []> tm = new HashMap <>();
501502 tm .put ("HyperLedgerFabric" , "InstantiateProposalRequest:JavaSDK" .getBytes (UTF_8 ));
502503 tm .put ("method" , "InstantiateProposalRequest" .getBytes (UTF_8 ));
@@ -510,7 +511,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
510511 chaincodeEndorsementPolicy .fromYamlFile (new File (TEST_FIXTURES_PATH + "/sdkintegration/chaincodeendorsementpolicy.yaml" ));
511512 instantiateProposalRequest .setChaincodeEndorsementPolicy (chaincodeEndorsementPolicy );
512513
513- out ("Sending instantiateProposalRequest to all peers with arguments: a and b set to 100 and %s respectively" , "" + (200 + delta ));
514+ out ("Sending instantiateProposalRequest to all peers with arguments: a and b set to 100 and %s respectively" , String . valueOf (200 + delta ));
514515 successful .clear ();
515516 failed .clear ();
516517
@@ -541,7 +542,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
541542 }
542543 ///////////////
543544 /// Send instantiate transaction to orderer
544- out ("Sending instantiateTransaction to orderer with a and b set to 100 and %s respectively" , "" + (200 + delta ));
545+ out ("Sending instantiateTransaction to orderer with a and b set to 100 and %s respectively" , String . valueOf (200 + delta ));
545546
546547 //Specify what events should complete the interest in this transaction. This is the default
547548 // for all to complete. It's possible to specify many different combinations like
@@ -692,10 +693,10 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
692693 ////////////////////////////
693694 // Send Query Proposal to all peers
694695 //
695- String expect = "" + (300 + delta );
696+ String expect = String . valueOf (300 + delta );
696697 out ("Now query chaincode for the value of b." );
697698 QueryByChaincodeRequest queryByChaincodeRequest = client .newQueryProposalRequest ();
698- queryByChaincodeRequest .setArgs (new String [] { "b" } );
699+ queryByChaincodeRequest .setArgs ("b" );
699700 queryByChaincodeRequest .setFcn ("query" );
700701 queryByChaincodeRequest .setChaincodeID (chaincodeID );
701702
@@ -704,16 +705,19 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
704705 tm2 .put ("method" , "QueryByChaincodeRequest" .getBytes (UTF_8 ));
705706 queryByChaincodeRequest .setTransientMap (tm2 );
706707
707- Collection <ProposalResponse > queryProposals = channel .queryByChaincode (queryByChaincodeRequest , channel .getPeers ());
708- for (ProposalResponse proposalResponse : queryProposals ) {
709- if (!proposalResponse .isVerified () || proposalResponse .getStatus () != ProposalResponse .Status .SUCCESS ) {
710- fail ("Failed query proposal from peer " + proposalResponse .getPeer ().getName () + " status: " + proposalResponse .getStatus () +
711- ". Messages: " + proposalResponse .getMessage ()
712- + ". Was verified : " + proposalResponse .isVerified ());
713- } else {
714- String payload = proposalResponse .getProposalResponse ().getResponse ().getPayload ().toStringUtf8 ();
715- out ("Query payload of b from peer %s returned %s" , proposalResponse .getPeer ().getName (), payload );
716- assertEquals (payload , expect );
708+ // Try each peer in turn just to confirm the request object can be reused
709+ for (Peer peer : channel .getPeers ()) {
710+ Collection <ProposalResponse > queryProposals = channel .queryByChaincode (queryByChaincodeRequest , Collections .singletonList (peer ));
711+ for (ProposalResponse proposalResponse : queryProposals ) {
712+ if (!proposalResponse .isVerified () || proposalResponse .getStatus () != ProposalResponse .Status .SUCCESS ) {
713+ fail ("Failed query proposal from peer " + proposalResponse .getPeer ().getName () + " status: " + proposalResponse .getStatus () +
714+ ". Messages: " + proposalResponse .getMessage ()
715+ + ". Was verified : " + proposalResponse .isVerified ());
716+ } else {
717+ String payload = proposalResponse .getProposalResponse ().getResponse ().getPayload ().toStringUtf8 ();
718+ out ("Query payload of b from peer %s returned %s" , proposalResponse .getPeer ().getName (), payload );
719+ assertEquals (payload , expect );
720+ }
717721 }
718722 }
719723
@@ -798,7 +802,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
798802 assertEquals (chaincodeEventListenerHandle , chaincodeEventCapture .handle );
799803 assertEquals (testTxID , chaincodeEventCapture .chaincodeEvent .getTxId ());
800804 assertEquals (EXPECTED_EVENT_NAME , chaincodeEventCapture .chaincodeEvent .getEventName ());
801- assertTrue ( Arrays . equals ( EXPECTED_EVENT_DATA , chaincodeEventCapture .chaincodeEvent .getPayload () ));
805+ assertArrayEquals ( EXPECTED_EVENT_DATA , chaincodeEventCapture .chaincodeEvent .getPayload ());
802806 assertEquals (CHAIN_CODE_NAME , chaincodeEventCapture .chaincodeEvent .getChaincodeId ());
803807
804808 BlockEvent blockEvent = chaincodeEventCapture .blockEvent ;
@@ -945,8 +949,8 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
945949 out (" Transaction number %d has channel id: %s" , i , channelId );
946950 out (" Transaction number %d has epoch: %d" , i , envelopeInfo .getEpoch ());
947951 out (" Transaction number %d has transaction timestamp: %tB %<te, %<tY %<tT %<Tp" , i , envelopeInfo .getTimestamp ());
948- out (" Transaction number %d has type id: %s" , i , "" + envelopeInfo .getType ());
949- out (" Transaction number %d has nonce : %s" , i , "" + Hex .encodeHexString (envelopeInfo .getNonce ()));
952+ out (" Transaction number %d has type id: %s" , i , envelopeInfo .getType ());
953+ out (" Transaction number %d has nonce : %s" , i , Hex .encodeHexString (envelopeInfo .getNonce ()));
950954 out (" Transaction number %d has submitter mspid: %s, certificate: %s" , i , envelopeInfo .getCreator ().getMspid (), envelopeInfo .getCreator ().getId ());
951955
952956 if (envelopeInfo .getType () == TRANSACTION_ENVELOPE ) {
@@ -956,7 +960,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
956960 out (" Transaction number %d has %d actions" , i , transactionEnvelopeInfo .getTransactionActionInfoCount ());
957961 assertEquals (1 , transactionEnvelopeInfo .getTransactionActionInfoCount ()); // for now there is only 1 action per transaction.
958962 out (" Transaction number %d isValid %b" , i , transactionEnvelopeInfo .isValid ());
959- assertEquals (transactionEnvelopeInfo .isValid (), true );
963+ assertTrue (transactionEnvelopeInfo .isValid ());
960964 out (" Transaction number %d validation code %d" , i , transactionEnvelopeInfo .getValidationCode ());
961965 assertEquals (0 , transactionEnvelopeInfo .getValidationCode ());
962966
@@ -999,7 +1003,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
9991003 ChaincodeEvent chaincodeEvent = transactionActionInfo .getEvent ();
10001004 assertNotNull (chaincodeEvent );
10011005
1002- assertTrue ( Arrays . equals ( EXPECTED_EVENT_DATA , chaincodeEvent .getPayload () ));
1006+ assertArrayEquals ( EXPECTED_EVENT_DATA , chaincodeEvent .getPayload ());
10031007 assertEquals (testTxID , chaincodeEvent .getTxId ());
10041008 assertEquals (CHAIN_CODE_NAME , chaincodeEvent .getChaincodeId ());
10051009 assertEquals (EXPECTED_EVENT_NAME , chaincodeEvent .getEventName ());
@@ -1076,7 +1080,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
10761080 }
10771081 }
10781082 if (!TX_EXPECTED .isEmpty ()) {
1079- fail (TX_EXPECTED .get ( 0 ));
1083+ fail (TX_EXPECTED .values (). toString ( ));
10801084 }
10811085 } catch (InvalidProtocolBufferRuntimeException e ) {
10821086 throw e .getCause ();
0 commit comments