Skip to content

Commit

Permalink
Changed the response model of show anchor peer API
Browse files Browse the repository at this point in the history
Signed-off-by: n0s09by <Nidhi.singh0@walmart.com>
  • Loading branch information
nidhi-singh02 committed Feb 20, 2024
1 parent 603fc0c commit b23fe19
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,9 +35,9 @@ public class FabricOperationsController {
* channel
*/
@GetMapping(value = "/channel/{channelName}/anchor_peers")
public ResponseEntity<ClientResponseModel> getAnchorPeerForChannel(
public ResponseEntity<Set<String>> getAnchorPeerForChannel(
@PathVariable @Validated String channelName) {
return networkStatus.getAnchorPeerForChannel(channelName);
return new ResponseEntity<>(networkStatus.getAnchorPeerForChannel(channelName), HttpStatus.OK);
}
/**
* Obtain the channel configuration details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientResponseModel> getChannelFromNetwork(String channelName);

ResponseEntity<ClientResponseModel> getAnchorPeerForChannel(String channelName);
Set<String> getAnchorPeerForChannel(String channelName);

ResponseEntity<ClientResponseModel> signChannelConfigTransaction(
String channelName, String configUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,9 +89,8 @@ private Set<String> getAnchorPeersFromOrgConfigGroup(
}

@Override
public ResponseEntity<ClientResponseModel> getAnchorPeerForChannel(String channelName) {
public Set<String> getAnchorPeerForChannel(String channelName) {
Network network = gateway.getNetwork(channelName);
Set<String> anchorPeersSet = new HashSet<>();
try {
if (network != null) {
Channel selectedChannel = network.getChannel();
Expand All @@ -105,7 +103,7 @@ public ResponseEntity<ClientResponseModel> getAnchorPeerForChannel(String channe
// Get all MSP IDs for a particular channel
Collection<String> peersOrganizationMSPIDs = selectedChannel.getPeersOrganizationMSPIDs();
log.debug("peersOrganizationMSPIDs: {}", peersOrganizationMSPIDs.toString());
anchorPeersSet = getAnchorPeersFromOrgConfigGroup(peersOrganizationMSPIDs, application);
return getAnchorPeersFromOrgConfigGroup(peersOrganizationMSPIDs, application);
}

} catch (InvalidArgumentException e) {
Expand All @@ -126,9 +124,7 @@ public ResponseEntity<ClientResponseModel> 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
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/hlf/java/rest/client/IT/ChannelIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void channelJoinForTwoOrgsTest() {
}

@Test
@Order(6)
@Order(7)
public void addOrgToChannelTest() {
ChannelUpdateParamsDTO newOrgParamsDTO = new ChannelUpdateParamsDTO();
try {
Expand Down Expand Up @@ -339,7 +339,7 @@ public void addOrgToChannelTest() {
}

@Test
@Order(7)
@Order(6)
public void addAnchorPeersToChannelTest() {
ChannelUpdateParamsDTO channelUpdateParamsDTO = new ChannelUpdateParamsDTO();
channelUpdateParamsDTO.setOrganizationMspId(ORG_1_MSP);
Expand All @@ -356,9 +356,8 @@ public void addAnchorPeersToChannelTest() {

@Test
@Order(8)
public void getAnchorPeerForChannelTest() {
ResponseEntity<ClientResponseModel> responseModel =
networkStatus.getAnchorPeerForChannel(CHANNEL_NAME_TWO_ORGS);
Assertions.assertEquals(new Integer(200), responseModel.getStatusCodeValue());
public void getAnchorPeerForChannelWithoutAnchorPeersTest() {
Set<String> anchorPeersSet = networkStatus.getAnchorPeerForChannel(CHANNEL_NAME);
Assertions.assertEquals(new Integer(0), anchorPeersSet.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,9 +28,10 @@ public class FabricOperationsControllerTest {

@Test
public void getAnchorPeerForChannelTest() {
ResponseEntity responseEntity = new ResponseEntity(HttpStatus.OK);
ResponseEntity<Set<String>> 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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ public class NetworkStatusImplTest {

@Test
public void getAnchorPeerForChannelTest() throws InvalidArgumentException, TransactionException {
ResponseEntity<ClientResponseModel> 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]);
Expand All @@ -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
Expand Down

0 comments on commit b23fe19

Please sign in to comment.