@Before public void setUp() { networkDeviceHelper = new NetworkDeviceHelperImpl(interfaceDao, hostDeviceDao, hostNicVfsConfigDao, vdsDao); when(netDevice.getHostId()).thenReturn(HOST_ID); when(netDevice.getDeviceName()).thenReturn(NET_DEVICE_NAME); when(netDevice.getName()).thenReturn(NET_DEVICE_NAME); when(netDevice.getNetworkInterfaceName()).thenReturn(NIC_NAME); when(netDevice.getParentDeviceName()).thenReturn(PCI_DEVICE_NAME); when(pciDevice.getHostId()).thenReturn(HOST_ID); when(pciDevice.getDeviceName()).thenReturn(PCI_DEVICE_NAME); when(pciDevice.getName()).thenReturn(PCI_DEVICE_NAME); List<HostDevice> devices = new ArrayList<>(); devices.add(netDevice); devices.add(pciDevice); mockHostDevices(devices); when(nic.getId()).thenReturn(NIC_ID); when(nic.getName()).thenReturn(NIC_NAME); when(nic.getVdsId()).thenReturn(HOST_ID); when(interfaceDao.get(NIC_ID)).thenReturn(nic); when(nic.getName()).thenReturn(NIC_NAME); when(hostNicVfsConfig.getNicId()).thenReturn(NIC_ID); when(hostNicVfsConfigDao.getByNicId(NIC_ID)).thenReturn(hostNicVfsConfig); }
@Test public void getHostNicVfsConfigsWithNumVfsDataByHostId() { when(hostNicVfsConfigDao.getAllVfsConfigByHostId(HOST_ID)) .thenReturn(Collections.singletonList(hostNicVfsConfig)); when(pciDevice.getTotalVirtualFunctions()).thenReturn(TOTAL_NUM_OF_VFS); List<HostDevice> vfs = mockVfsOnNetDevice(2); mockHostDevices(vfs); List<HostNicVfsConfig> vfsConfigList = networkDeviceHelper.getHostNicVfsConfigsWithNumVfsDataByHostId(HOST_ID); assertEquals(1, vfsConfigList.size()); assertEquals(hostNicVfsConfig, vfsConfigList.get(0)); verify(hostNicVfsConfig).setMaxNumOfVfs(TOTAL_NUM_OF_VFS); verify(hostNicVfsConfig).setNumOfVfs(2); }