From 1f3e02865f79b14422d69f018a1c3df924bd49f1 Mon Sep 17 00:00:00 2001 From: n0s09by Date: Mon, 12 Feb 2024 15:35:28 +0530 Subject: [PATCH 1/3] Capability to get anchor peer nodes in a channel introduced Signed-off-by: n0s09by --- .../FabricOperationsController.java | 12 ++++ .../rest/client/service/NetworkStatus.java | 2 + .../service/impl/NetworkStatusImpl.java | 69 +++++++++++++++++++ .../hlf/java/rest/client/IT/ChannelIT.java | 10 ++- .../FabricOperationsControllerTest.java | 9 +++ .../service/impl/NetworkStatusImplTest.java | 27 +++++++- 6 files changed, 127 insertions(+), 2 deletions(-) diff --git a/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java b/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java index 1839d34..c9a0971 100644 --- a/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java +++ b/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java @@ -25,6 +25,18 @@ public class FabricOperationsController { @Autowired private SerializationUtil serializationUtil; + /** + * Get the anchor peers defined in a channel. + * + * @param channelName - the name of the channel for which you will retrieve the anchor peer nodes + * @return ResponseEntity - contains the list of anchor peers in a particular + * channel + */ + @GetMapping(value = "/channel/{channelName}/anchor_peers") + public ResponseEntity getAnchorPeerForChannel( + @PathVariable @Validated String channelName) { + return networkStatus.getAnchorPeerForChannel(channelName); + } /** * Obtain the channel configuration details. * diff --git a/src/main/java/hlf/java/rest/client/service/NetworkStatus.java b/src/main/java/hlf/java/rest/client/service/NetworkStatus.java index 7d0fdd3..ee0cf96 100644 --- a/src/main/java/hlf/java/rest/client/service/NetworkStatus.java +++ b/src/main/java/hlf/java/rest/client/service/NetworkStatus.java @@ -9,6 +9,8 @@ public interface NetworkStatus { ResponseEntity getChannelFromNetwork(String channelName); + ResponseEntity getAnchorPeerForChannel(String channelName); + ResponseEntity signChannelConfigTransaction( String channelName, String configUpdate); diff --git a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java index 93c96d1..fc80ad1 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java @@ -15,16 +15,24 @@ import hlf.java.rest.client.service.ChannelConfigDeserialization; import hlf.java.rest.client.service.NetworkStatus; import hlf.java.rest.client.service.UpdateChannel; +import hlf.java.rest.client.util.FabricClientConstants; import java.io.IOException; +import java.io.Serializable; import java.util.ArrayList; import java.util.Base64; +import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.hyperledger.fabric.gateway.Gateway; import org.hyperledger.fabric.gateway.Network; +import org.hyperledger.fabric.protos.common.Configtx; import org.hyperledger.fabric.protos.common.Configtx.Config; import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup; import org.hyperledger.fabric.protos.common.Configtx.ConfigUpdate; +import org.hyperledger.fabric.protos.peer.Configuration; import org.hyperledger.fabric.sdk.Channel; import org.hyperledger.fabric.sdk.UpdateChannelConfiguration; import org.hyperledger.fabric.sdk.User; @@ -55,6 +63,67 @@ private String getDeserializedConfig(MessageOrBuilder message) { return Base64.getEncoder().encodeToString(channelConfigString.getBytes()); } + @Override + public ResponseEntity getAnchorPeerForChannel(String channelName) { + Network network = gateway.getNetwork(channelName); + Set anchorPeersSet = new HashSet<>(); + try { + if (network != null) { + Channel selectedChannel = network.getChannel(); + byte[] selectedChannelBytes = selectedChannel.getChannelConfigurationBytes(); + log.debug("peers: {} ", selectedChannel.getPeers()); + Map groupsMap = + Config.parseFrom(selectedChannelBytes).getChannelGroup().getGroupsMap(); + ConfigGroup application = + groupsMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION); + // Get all MSP IDs for a particular channel + Collection peersOrganizationMSPIDs = selectedChannel.getPeersOrganizationMSPIDs(); + log.debug("peersOrganizationMSPIDs: {}", peersOrganizationMSPIDs.toString()); + for (String peerOrganizationMSPID : peersOrganizationMSPIDs) { + ConfigGroup peerOrgConfigGroup = application.getGroupsMap().get(peerOrganizationMSPID); + if (peerOrgConfigGroup != null) { + Map valuesMap = peerOrgConfigGroup.getValuesMap(); + Configtx.ConfigValue anchorPeers = + valuesMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_VALUE_ANCHORPEERS); + if (null != anchorPeers && anchorPeers.getValue() != null) { + Configuration.AnchorPeers anchorPeersValue = + Configuration.AnchorPeers.parseFrom(anchorPeers.getValue()); + List anchorPeersList = + anchorPeersValue.getAnchorPeersList(); + if (anchorPeersList != null) { + for (Configuration.AnchorPeer anchorPeer : anchorPeersList) { + // Concatenating the host and port to form a URL + anchorPeersSet.add(anchorPeer.getHost() + ":" + anchorPeer.getPort()); + } + } + } + } + } + } + + } catch (InvalidArgumentException e) { + log.warn( + "Error while fetching channel config: Channel has no peer or orderer defined. Can not get configuration block"); + throw new ServiceException( + ErrorCode.HYPERLEDGER_FABRIC_TRANSACTION_ERROR, + "Channel has no peer or orderer defined. Can not get configuration block", + e); + } catch (TransactionException e) { + log.warn("Error retrieving anchor peers: {} ", e.getMessage()); + throw new FabricTransactionException( + ErrorCode.HYPERLEDGER_FABRIC_TRANSACTION_ERROR, + ErrorCode.HYPERLEDGER_FABRIC_TRANSACTION_ERROR.name(), + e); + } catch (InvalidProtocolBufferException e) { + log.warn("Error retrieving anchor peers: {}", e.getMessage()); + throw new ServiceException( + ErrorCode.HYPERLEDGER_FABRIC_TRANSACTION_ERROR, "Error retrieving anchor peers", e); + } + return new ResponseEntity<>( + new ClientResponseModel(ErrorConstants.NO_ERROR, (Serializable) anchorPeersSet), + HttpStatus.OK); + } + @Override /** * Obtains the channel configuration diff --git a/src/test/java/hlf/java/rest/client/IT/ChannelIT.java b/src/test/java/hlf/java/rest/client/IT/ChannelIT.java index 4675c33..56d2fa1 100644 --- a/src/test/java/hlf/java/rest/client/IT/ChannelIT.java +++ b/src/test/java/hlf/java/rest/client/IT/ChannelIT.java @@ -350,7 +350,15 @@ public void addAnchorPeersToChannelTest() { anchorPeerDTOs.add(anchorPeerDTO); channelUpdateParamsDTO.setAnchorPeerDTOs(anchorPeerDTOs); ResponseEntity responseModel = - networkStatus.addAnchorPeersToChannel(CHANNEL_NAME, channelUpdateParamsDTO); + networkStatus.addAnchorPeersToChannel(CHANNEL_NAME_TWO_ORGS, channelUpdateParamsDTO); + Assertions.assertEquals(new Integer(200), responseModel.getStatusCodeValue()); + } + + @Test + @Order(8) + public void getAnchorPeerForChannelTest() { + ResponseEntity responseModel = + networkStatus.getAnchorPeerForChannel(CHANNEL_NAME_TWO_ORGS); Assertions.assertEquals(new Integer(200), responseModel.getStatusCodeValue()); } } diff --git a/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java b/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java index e326e75..e90b75c 100644 --- a/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java +++ b/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java @@ -24,6 +24,15 @@ public class FabricOperationsControllerTest { @Mock private NetworkStatus networkStatus; @Mock private SerializationUtil serializationUtil; + @Test + public void getAnchorPeerForChannelTest() { + ResponseEntity responseEntity = new ResponseEntity(HttpStatus.OK); + Mockito.when(networkStatus.getAnchorPeerForChannel(Mockito.anyString())) + .thenReturn(responseEntity); + assertEquals( + responseEntity, fabricOperationsController.getAnchorPeerForChannel("some_channel_name")); + } + @Test public void getChannelConfigurationTest() { ResponseEntity responseEntity = new ResponseEntity(HttpStatus.OK); diff --git a/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java b/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java index eaefa11..4540004 100644 --- a/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java +++ b/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java @@ -15,11 +15,15 @@ import hlf.java.rest.client.model.CommitChannelParamsDTO; import hlf.java.rest.client.model.MSPDTO; import hlf.java.rest.client.service.ChannelConfigDeserialization; +import hlf.java.rest.client.util.FabricClientConstants; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Map; import org.hyperledger.fabric.gateway.Network; import org.hyperledger.fabric.gateway.impl.GatewayImpl; +import org.hyperledger.fabric.protos.common.Configtx; import org.hyperledger.fabric.protos.common.Configtx.Config; import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup; import org.hyperledger.fabric.protos.common.Configtx.ConfigUpdate; @@ -88,7 +92,28 @@ public class NetworkStatusImplTest { @Mock private ByteString byteString; - @Mock private ConfigUpdate.Builder configUpdateBuilder; + @Mock private Configtx.Config configTxConfig; + @Mock private Configtx.ConfigGroup configTxConfigGroup; + + @Mock private Map groupMap; + + @Test + public void getAnchorPeerForChannelTest() throws InvalidArgumentException, TransactionException { + ResponseEntity responseEntity = + new ResponseEntity<>( + new ClientResponseModel(ErrorConstants.NO_ERROR, new HashSet<>()), HttpStatus.OK); + Mockito.when(gateway.getNetwork(Mockito.anyString())).thenReturn(network); + Mockito.when(network.getChannel()).thenReturn(channel); + Mockito.when(channel.getChannelConfigurationBytes()).thenReturn(new byte[0]); + staticConfig.when(() -> Config.parseFrom(Mockito.any(byte[].class))).thenReturn(configTxConfig); + Mockito.when(configTxConfig.getChannelGroup()).thenReturn(configTxConfigGroup); + Mockito.when(configTxConfigGroup.getGroupsMap()).thenReturn(groupMap); + Mockito.when(groupMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION)) + .thenReturn(readset); + assertEquals( + responseEntity.getStatusCode(), + networkStatus.getAnchorPeerForChannel("some_channelname").getStatusCode()); + } @Test public void getChannelFromNetworkTest() From 603fc0cc4904548f32f49915b8e9c42fd6c99e22 Mon Sep 17 00:00:00 2001 From: n0s09by Date: Mon, 19 Feb 2024 10:13:00 +0530 Subject: [PATCH 2/3] Refactor the code to make it modular Signed-off-by: n0s09by --- .../service/impl/NetworkStatusImpl.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java index fc80ad1..f0f2c36 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java @@ -63,6 +63,32 @@ private String getDeserializedConfig(MessageOrBuilder message) { return Base64.getEncoder().encodeToString(channelConfigString.getBytes()); } + private Set getAnchorPeersFromOrgConfigGroup( + Collection peersOrganizationMSPIDs, ConfigGroup application) + throws InvalidProtocolBufferException { + Set anchorPeersSet = new HashSet<>(); + for (String peerOrganizationMSPID : peersOrganizationMSPIDs) { + ConfigGroup peerOrgConfigGroup = application.getGroupsMap().get(peerOrganizationMSPID); + if (peerOrgConfigGroup != null) { + Map valuesMap = peerOrgConfigGroup.getValuesMap(); + Configtx.ConfigValue anchorPeers = + valuesMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_VALUE_ANCHORPEERS); + if (null != anchorPeers && anchorPeers.getValue() != null) { + Configuration.AnchorPeers anchorPeersValue = + Configuration.AnchorPeers.parseFrom(anchorPeers.getValue()); + List anchorPeersList = anchorPeersValue.getAnchorPeersList(); + if (anchorPeersList != null) { + for (Configuration.AnchorPeer anchorPeer : anchorPeersList) { + // Concatenating the host and port to form a URL + anchorPeersSet.add(anchorPeer.getHost() + ":" + anchorPeer.getPort()); + } + } + } + } + } + return anchorPeersSet; + } + @Override public ResponseEntity getAnchorPeerForChannel(String channelName) { Network network = gateway.getNetwork(channelName); @@ -79,26 +105,7 @@ public ResponseEntity getAnchorPeerForChannel(String channe // Get all MSP IDs for a particular channel Collection peersOrganizationMSPIDs = selectedChannel.getPeersOrganizationMSPIDs(); log.debug("peersOrganizationMSPIDs: {}", peersOrganizationMSPIDs.toString()); - for (String peerOrganizationMSPID : peersOrganizationMSPIDs) { - ConfigGroup peerOrgConfigGroup = application.getGroupsMap().get(peerOrganizationMSPID); - if (peerOrgConfigGroup != null) { - Map valuesMap = peerOrgConfigGroup.getValuesMap(); - Configtx.ConfigValue anchorPeers = - valuesMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_VALUE_ANCHORPEERS); - if (null != anchorPeers && anchorPeers.getValue() != null) { - Configuration.AnchorPeers anchorPeersValue = - Configuration.AnchorPeers.parseFrom(anchorPeers.getValue()); - List anchorPeersList = - anchorPeersValue.getAnchorPeersList(); - if (anchorPeersList != null) { - for (Configuration.AnchorPeer anchorPeer : anchorPeersList) { - // Concatenating the host and port to form a URL - anchorPeersSet.add(anchorPeer.getHost() + ":" + anchorPeer.getPort()); - } - } - } - } - } + anchorPeersSet = getAnchorPeersFromOrgConfigGroup(peersOrganizationMSPIDs, application); } } catch (InvalidArgumentException e) { From b23fe19735267fadd80b22fe1ed75b50b0541f5c Mon Sep 17 00:00:00 2001 From: n0s09by Date: Tue, 20 Feb 2024 10:43:40 +0530 Subject: [PATCH 3/3] Changed the response model of show anchor peer API Signed-off-by: n0s09by --- .../client/controller/FabricOperationsController.java | 6 ++++-- .../hlf/java/rest/client/service/NetworkStatus.java | 3 ++- .../rest/client/service/impl/NetworkStatusImpl.java | 10 +++------- src/test/java/hlf/java/rest/client/IT/ChannelIT.java | 11 +++++------ .../controller/FabricOperationsControllerTest.java | 7 +++++-- .../client/service/impl/NetworkStatusImplTest.java | 7 +------ 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java b/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java index c9a0971..735675d 100644 --- a/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java +++ b/src/main/java/hlf/java/rest/client/controller/FabricOperationsController.java @@ -5,8 +5,10 @@ import hlf.java.rest.client.model.CommitChannelParamsDTO; import hlf.java.rest.client.service.NetworkStatus; import hlf.java.rest.client.util.SerializationUtil; +import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -33,9 +35,9 @@ public class FabricOperationsController { * channel */ @GetMapping(value = "/channel/{channelName}/anchor_peers") - public ResponseEntity getAnchorPeerForChannel( + public ResponseEntity> getAnchorPeerForChannel( @PathVariable @Validated String channelName) { - return networkStatus.getAnchorPeerForChannel(channelName); + return new ResponseEntity<>(networkStatus.getAnchorPeerForChannel(channelName), HttpStatus.OK); } /** * Obtain the channel configuration details. diff --git a/src/main/java/hlf/java/rest/client/service/NetworkStatus.java b/src/main/java/hlf/java/rest/client/service/NetworkStatus.java index ee0cf96..0050707 100644 --- a/src/main/java/hlf/java/rest/client/service/NetworkStatus.java +++ b/src/main/java/hlf/java/rest/client/service/NetworkStatus.java @@ -3,13 +3,14 @@ import hlf.java.rest.client.model.ChannelUpdateParamsDTO; import hlf.java.rest.client.model.ClientResponseModel; import hlf.java.rest.client.model.CommitChannelParamsDTO; +import java.util.Set; import org.springframework.http.ResponseEntity; public interface NetworkStatus { ResponseEntity getChannelFromNetwork(String channelName); - ResponseEntity getAnchorPeerForChannel(String channelName); + Set getAnchorPeerForChannel(String channelName); ResponseEntity signChannelConfigTransaction( String channelName, String configUpdate); diff --git a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java index f0f2c36..62a96ba 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java @@ -17,7 +17,6 @@ import hlf.java.rest.client.service.UpdateChannel; import hlf.java.rest.client.util.FabricClientConstants; import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; import java.util.Base64; import java.util.Collection; @@ -90,9 +89,8 @@ private Set getAnchorPeersFromOrgConfigGroup( } @Override - public ResponseEntity getAnchorPeerForChannel(String channelName) { + public Set getAnchorPeerForChannel(String channelName) { Network network = gateway.getNetwork(channelName); - Set anchorPeersSet = new HashSet<>(); try { if (network != null) { Channel selectedChannel = network.getChannel(); @@ -105,7 +103,7 @@ public ResponseEntity getAnchorPeerForChannel(String channe // Get all MSP IDs for a particular channel Collection peersOrganizationMSPIDs = selectedChannel.getPeersOrganizationMSPIDs(); log.debug("peersOrganizationMSPIDs: {}", peersOrganizationMSPIDs.toString()); - anchorPeersSet = getAnchorPeersFromOrgConfigGroup(peersOrganizationMSPIDs, application); + return getAnchorPeersFromOrgConfigGroup(peersOrganizationMSPIDs, application); } } catch (InvalidArgumentException e) { @@ -126,9 +124,7 @@ public ResponseEntity getAnchorPeerForChannel(String channe throw new ServiceException( ErrorCode.HYPERLEDGER_FABRIC_TRANSACTION_ERROR, "Error retrieving anchor peers", e); } - return new ResponseEntity<>( - new ClientResponseModel(ErrorConstants.NO_ERROR, (Serializable) anchorPeersSet), - HttpStatus.OK); + return new HashSet<>(); } @Override diff --git a/src/test/java/hlf/java/rest/client/IT/ChannelIT.java b/src/test/java/hlf/java/rest/client/IT/ChannelIT.java index 56d2fa1..b2d7ae7 100644 --- a/src/test/java/hlf/java/rest/client/IT/ChannelIT.java +++ b/src/test/java/hlf/java/rest/client/IT/ChannelIT.java @@ -303,7 +303,7 @@ public void channelJoinForTwoOrgsTest() { } @Test - @Order(6) + @Order(7) public void addOrgToChannelTest() { ChannelUpdateParamsDTO newOrgParamsDTO = new ChannelUpdateParamsDTO(); try { @@ -339,7 +339,7 @@ public void addOrgToChannelTest() { } @Test - @Order(7) + @Order(6) public void addAnchorPeersToChannelTest() { ChannelUpdateParamsDTO channelUpdateParamsDTO = new ChannelUpdateParamsDTO(); channelUpdateParamsDTO.setOrganizationMspId(ORG_1_MSP); @@ -356,9 +356,8 @@ public void addAnchorPeersToChannelTest() { @Test @Order(8) - public void getAnchorPeerForChannelTest() { - ResponseEntity responseModel = - networkStatus.getAnchorPeerForChannel(CHANNEL_NAME_TWO_ORGS); - Assertions.assertEquals(new Integer(200), responseModel.getStatusCodeValue()); + public void getAnchorPeerForChannelWithoutAnchorPeersTest() { + Set anchorPeersSet = networkStatus.getAnchorPeerForChannel(CHANNEL_NAME); + Assertions.assertEquals(new Integer(0), anchorPeersSet.size()); } } diff --git a/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java b/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java index e90b75c..af9ce71 100644 --- a/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java +++ b/src/test/java/hlf/java/rest/client/controller/FabricOperationsControllerTest.java @@ -6,6 +6,8 @@ import hlf.java.rest.client.model.CommitChannelParamsDTO; import hlf.java.rest.client.service.NetworkStatus; import hlf.java.rest.client.util.SerializationUtil; +import java.util.HashSet; +import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -26,9 +28,10 @@ public class FabricOperationsControllerTest { @Test public void getAnchorPeerForChannelTest() { - ResponseEntity responseEntity = new ResponseEntity(HttpStatus.OK); + ResponseEntity> responseEntity = + new ResponseEntity<>(new HashSet<>(), HttpStatus.OK); Mockito.when(networkStatus.getAnchorPeerForChannel(Mockito.anyString())) - .thenReturn(responseEntity); + .thenReturn(new HashSet<>()); assertEquals( responseEntity, fabricOperationsController.getAnchorPeerForChannel("some_channel_name")); } diff --git a/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java b/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java index 4540004..f1cbbb7 100644 --- a/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java +++ b/src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java @@ -99,9 +99,6 @@ public class NetworkStatusImplTest { @Test public void getAnchorPeerForChannelTest() throws InvalidArgumentException, TransactionException { - ResponseEntity responseEntity = - new ResponseEntity<>( - new ClientResponseModel(ErrorConstants.NO_ERROR, new HashSet<>()), HttpStatus.OK); Mockito.when(gateway.getNetwork(Mockito.anyString())).thenReturn(network); Mockito.when(network.getChannel()).thenReturn(channel); Mockito.when(channel.getChannelConfigurationBytes()).thenReturn(new byte[0]); @@ -110,9 +107,7 @@ public void getAnchorPeerForChannelTest() throws InvalidArgumentException, Trans Mockito.when(configTxConfigGroup.getGroupsMap()).thenReturn(groupMap); Mockito.when(groupMap.get(FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION)) .thenReturn(readset); - assertEquals( - responseEntity.getStatusCode(), - networkStatus.getAnchorPeerForChannel("some_channelname").getStatusCode()); + assertEquals(new HashSet<>(), networkStatus.getAnchorPeerForChannel("some_channelname")); } @Test