HostResourcesService { protected List<VmResources> listVmsFromHost(HostResources host) { List<VMInstanceVO> vmInstanceList = vmInstanceDao.listByHostId(host.getHostId()); List<VmResources> vmResourcesList = new ArrayList<>(); for (VMInstanceVO vmInstance : vmInstanceList) { if (!isVmCurrentlyUsingHostResource(vmInstance)) { continue; } ServiceOfferingVO serviceOffering = serviceOfferingDao.findById(vmInstance.getServiceOfferingId()); vmResourcesList.add(new VmResources(vmInstance.getId(), serviceOffering.getCpu(), serviceOffering.getSpeed(), serviceOffering.getRamSize())); } return vmResourcesList; }  HostResources createAndConfigureHostResources(HostVO hostVo); HostResources createHostResources(HostVO hostVO);  }
@Test public void listVmsFromHostTest() { HostResources hostResources = Mockito.mock(HostResources.class); Mockito.when(hostResources.getHostId()).thenReturn(1l); ServiceOfferingVO serviceOfferingVO = new ServiceOfferingVO("name", 1, 512, 1000, 1000, 1000, true, "displayText", ProvisioningType.THIN, true, true, "tags", true, com.cloud.vm.VirtualMachine.Type.User, true); List<VMInstanceVO> vmsInstanceVO = createRunningVmIistanceVo(2); Mockito.when(vmInstanceDao.listByHostId(1l)).thenReturn(vmsInstanceVO); Mockito.when(serviceOfferingDao.findById(1l)).thenReturn(serviceOfferingVO); List<VmResources> vmResourcesList = hostResourcesService.listVmsFromHost(hostResources); Assert.assertEquals(2, vmResourcesList.size()); Assert.assertEquals(1000l, vmResourcesList.get(0).getCpuSpeed()); Assert.assertEquals(512l, vmResourcesList.get(1).getMemoryInMegaBytes()); Assert.assertEquals(1, vmResourcesList.get(0).getNumberOfCpus()); }