use of org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd in project cloudstack by apache.
the class UserVmManagerTest method testUpdateVmNicIpSuccess2.
@Test
public void testUpdateVmNicIpSuccess2() throws Exception {
UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
Class<?> _class = cmd.getClass();
Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
List<Service> services = new ArrayList<Service>();
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Running);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
when(_networkMock.getDataCenterId()).thenReturn(3L);
when(_networkMock.getGuestType()).thenReturn(GuestType.Shared);
when(_dcDao.findById(anyLong())).thenReturn(_dcMock);
when(_dcMock.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_ipAddrMgr.allocatePublicIpForGuestNic(Mockito.eq(_networkMock), anyLong(), Mockito.eq(_accountMock), anyString())).thenReturn("10.10.10.10");
when(_ipAddressDao.findByIpAndSourceNetworkId(anyLong(), anyString())).thenReturn(null);
when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
use of org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd in project cloudstack by apache.
the class UpdateVmNicIpTest method testSuccess.
@Test
public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
UserVmService userVmService = Mockito.mock(UserVmService.class);
updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
UserVm userVm = Mockito.mock(UserVm.class);
Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm);
updateVmNicIpCmd._userVmService = userVmService;
responseGenerator = Mockito.mock(ResponseGenerator.class);
List<UserVmResponse> list = new LinkedList<UserVmResponse>();
UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
list.add(userVmResponse);
Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
updateVmNicIpCmd._responseGenerator = responseGenerator;
updateVmNicIpCmd.execute();
}
Aggregations