@Test public void testCreateSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException { NetworkService networkService = Mockito.mock(NetworkService.class); AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class); NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class); Mockito.when( networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) .thenReturn(secIp); ipTonicCmd._networkService = networkService; responseGenerator = Mockito.mock(ResponseGenerator.class); NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class); Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres); ipTonicCmd._responseGenerator = responseGenerator; ipTonicCmd.execute(); }
if (results != null) { for (NicSecondaryIp r : results) { NicSecondaryIpResponse ipRes = _responseGenerator.createSecondaryIPToNicResponse(r); resList.add(ipRes); res.setSecondaryIpsList(resList);
@Override public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { CallContext.current().setEventDetails("Nic Id: " + this._uuidMgr.getUuid(Nic.class, getNicId())); NicSecondaryIp result = _entityMgr.findById(NicSecondaryIp.class, getEntityId()); if (result != null) { CallContext.current().setEventDetails("secondary Ip Id: " + getEntityUuid()); boolean success = false; success = _networkService.configureNicSecondaryIp(result, isZoneSGEnabled()); if (success == false) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip"); } NicSecondaryIpResponse response = _responseGenerator.createSecondaryIPToNicResponse(result); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic"); } }