Reference network = Iterables.getLast(networks);
// Copy existing section and edit fields
NetworkConnectionSection oldSection = vmApi
.getNetworkConnectionSection(vmUrn);
NetworkConnection newNetworkConnection = NetworkConnection.builder()
.network(network.getName()).networkConnectionIndex(1)
.ipAddressAllocationMode(IpAddressAllocationMode.DHCP).build();
NetworkConnectionSection newSection = oldSection.toBuilder()
.networkConnection(newNetworkConnection).build();
// The method under test
Task editNetworkConnectionSection = vmApi.editNetworkConnectionSection(
vmUrn, newSection);
assertTrue(retryTaskSuccess.apply(editNetworkConnectionSection),
String.format(TASK_COMPLETE_TIMELY,
"editNetworkConnectionSection"));
// Retrieve the modified section
NetworkConnectionSection modified = vmApi
.getNetworkConnectionSection(vmUrn);
// Check the retrieved object is well formed
checkNetworkConnectionSection(modified);
// Check the section was modified correctly
for (NetworkConnection connection : modified.getNetworkConnections()) {
if (connection.getNetwork().equals(
newNetworkConnection.getNetwork())) {
assertEquals(connection.getIpAddressAllocationMode(),
newNetworkConnection.getIpAddressAllocationMode());
assertSame(connection.getNetworkConnectionIndex(), newNetworkConnection
.getNetworkConnectionIndex());
}
}
}