Skip to content

Commit 0984d62

Browse files
n0s09byn0s09by
authored andcommitted
validation and test modification
Signed-off-by: n0s09by <[email protected]>
1 parent dddc7a2 commit 0984d62

File tree

3 files changed

+42
-43
lines changed

3 files changed

+42
-43
lines changed

src/main/java/hlf/java/rest/client/service/impl/NetworkStatusImpl.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public ResponseEntity<ClientResponseModel> generateConfigUpdate(
127127
private ConfigUpdate createConfigUpdate(
128128
String channelName, ChannelUpdateParamsDTO organizationDetails) {
129129
Network network = gateway.getNetwork(channelName);
130-
if (network != null) {
130+
if (network != null && organizationDetails.getMspDTO() != null) {
131131
try {
132132
Channel selectedChannel = network.getChannel();
133133
byte[] channelConfigBytes = selectedChannel.getChannelConfigurationBytes();
@@ -178,7 +178,11 @@ private ConfigUpdate createConfigUpdate(
178178
}
179179
} else {
180180
log.warn(
181-
"Error fetching the channel config: Network cannot be NULL: " + "Network = " + network);
181+
"Error fetching the channel config: Network and MSP details cannot be NULL: "
182+
+ "Network = "
183+
+ network
184+
+ " MSP details = "
185+
+ organizationDetails.getMspDTO());
182186
return ConfigUpdate.newBuilder().build();
183187
}
184188
}
@@ -321,7 +325,7 @@ public ResponseEntity<ClientResponseModel> commitChannelConfigTransaction(
321325
public ResponseEntity<ClientResponseModel> addOrgToChannel(
322326
String channelName, ChannelUpdateParamsDTO organizationDetails) {
323327
Network network = gateway.getNetwork(channelName);
324-
if (network != null && user != null) {
328+
if (network != null && user != null && organizationDetails.getMspDTO() != null) {
325329
try {
326330
Channel selectedChannel = network.getChannel();
327331
ConfigUpdate configUpdate = createConfigUpdate(channelName, organizationDetails);
@@ -358,11 +362,24 @@ public ResponseEntity<ClientResponseModel> addOrgToChannel(
358362
new ClientResponseModel(ErrorConstants.NO_ERROR, ErrorCode.SUCCESS.getReason()),
359363
HttpStatus.OK);
360364
} else {
361-
log.warn("Network and User cannot be NULL: " + "Network = " + network + "and User = " + user);
365+
log.warn(
366+
"Network, User and MSP details cannot be NULL: "
367+
+ "Network = "
368+
+ network
369+
+ " User = "
370+
+ user
371+
+ " and MSP details = "
372+
+ organizationDetails.getMspDTO());
362373
return new ResponseEntity<>(
363374
new ClientResponseModel(
364375
ErrorCode.NOT_FOUND.getValue(),
365-
"Network and User cannot be NULL: " + "Network = " + network + "and User = " + user),
376+
"Network, User and MSP details cannot be NULL: "
377+
+ "Network = "
378+
+ network
379+
+ " User = "
380+
+ user
381+
+ " and MSP details = "
382+
+ organizationDetails.getMspDTO()),
366383
HttpStatus.OK);
367384
}
368385
}

src/main/java/hlf/java/rest/client/service/impl/UpdateChannelImpl.java

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,21 @@ public ConfigGroup buildWriteset(ConfigGroup readset, ChannelUpdateParamsDTO org
3232
Map<String, ConfigGroup> existingOrganizations =
3333
FabricChannelUtil.getExistingOrgsFromReadset(readset);
3434

35-
ConfigGroup applicationGroup;
36-
37-
if (organizationDetails.getMspDTO() != null) {
38-
// New org addition scenario
39-
// The "Application" group
40-
applicationGroup =
41-
ConfigGroup.newBuilder()
42-
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS)
43-
.putAllPolicies(FabricChannelUtil.setApplicationPolicies(readset))
44-
.putGroups(newOrgMspId, setNewOrgGroup(newOrgMspId, organizationDetails))
45-
// putAllGroups excludes new organization
46-
.putAllGroups(existingOrganizations)
47-
// Application group version
48-
.setVersion(
49-
FabricChannelUtil.retrieveMSPGroupVersionFromReadset(
50-
readset, FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION)
51-
+ 1) // will be tied to current version + 1 for this level
52-
.build();
53-
} else {
54-
// The "Application" group
55-
applicationGroup =
56-
ConfigGroup.newBuilder()
57-
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS)
58-
.putAllPolicies(FabricChannelUtil.setApplicationPolicies(readset))
59-
.putGroups(
60-
newOrgMspId, setAnchorPeerInGroup(newOrgMspId, readset, organizationDetails))
61-
// putAllGroups excludes new organization
62-
.putAllGroups(existingOrganizations)
63-
// Application group version
64-
.setVersion(
65-
FabricChannelUtil.retrieveMSPGroupVersionFromReadset(
66-
readset, FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION)
67-
+ 1) // will be tied to current version + 1 for this level
68-
.build();
69-
}
70-
35+
// New org addition scenario
36+
// The "Application" group
37+
ConfigGroup applicationGroup =
38+
ConfigGroup.newBuilder()
39+
.setModPolicy(FabricClientConstants.CHANNEL_CONFIG_MOD_POLICY_ADMINS)
40+
.putAllPolicies(FabricChannelUtil.setApplicationPolicies(readset))
41+
.putGroups(newOrgMspId, setNewOrgGroup(newOrgMspId, organizationDetails))
42+
// putAllGroups excludes new organization
43+
.putAllGroups(existingOrganizations)
44+
// Application group version
45+
.setVersion(
46+
FabricChannelUtil.retrieveMSPGroupVersionFromReadset(
47+
readset, FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION)
48+
+ 1) // will be tied to current version + 1 for this level
49+
.build();
7150
// the "/Channel" group
7251
return ConfigGroup.newBuilder()
7352
.putGroups(FabricClientConstants.CHANNEL_CONFIG_GROUP_APPLICATION, applicationGroup)

src/test/java/hlf/java/rest/client/service/impl/NetworkStatusImplTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import hlf.java.rest.client.model.ChannelUpdateParamsDTO;
1414
import hlf.java.rest.client.model.ClientResponseModel;
1515
import hlf.java.rest.client.model.CommitChannelParamsDTO;
16+
import hlf.java.rest.client.model.MSPDTO;
1617
import hlf.java.rest.client.service.ChannelConfigDeserialization;
1718
import java.util.ArrayList;
1819
import java.util.Collections;
@@ -72,6 +73,7 @@ public class NetworkStatusImplTest {
7273
@Mock private ConfigGroup readset;
7374

7475
@Mock private ConfigGroup writeset;
76+
@Mock private MSPDTO mspdto;
7577

7678
@Mock private Builder builder;
7779

@@ -201,7 +203,6 @@ public void addOrgToChannelTest() throws InvalidArgumentException, TransactionEx
201203

202204
Mockito.when(gateway.getNetwork(Mockito.anyString())).thenReturn(network);
203205
Mockito.when(network.getChannel()).thenReturn(channel);
204-
205206
Mockito.when(channel.getChannelConfigurationBytes()).thenReturn(new byte[0]);
206207
staticConfigUpdate
207208
.when(() -> ConfigUpdate.parseFrom(Mockito.any(byte[].class)))
@@ -224,10 +225,12 @@ public void addOrgToChannelTest() throws InvalidArgumentException, TransactionEx
224225
Mockito.any(UpdateChannelConfiguration.class), Mockito.any(User.class)))
225226
.thenReturn(outputByteArray);
226227

228+
Mockito.when(channelUpdateParamsDTO.getMspDTO()).thenReturn(mspdto);
229+
227230
assertEquals(
228231
responseEntity.getBody().getMessage(),
229232
networkStatus
230-
.addOrgToChannel("some_channel_name", new ChannelUpdateParamsDTO())
233+
.addOrgToChannel("some_channel_name", channelUpdateParamsDTO)
231234
.getBody()
232235
.getMessage());
233236
}

0 commit comments

Comments
 (0)