AutonomiccsSystemVmDeploymentService implements InitializingBean { protected NetworkVO getDefaultNetworkForAdvancedNetworkingWithSecurityGroupds(long dataCenterId, DataCenterVO dc) { List<NetworkVO> networks = networkDao.listByZoneSecurityGroup(dataCenterId); if (CollectionUtils.isEmpty(networks)) { throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc); } return networks.get(0); }  HostVO searchForRandomHostInCloudToDeployAutonomiccsSystemVm(); HostVO searchForRandomHostInPodToDeployAutonomiccsSystemVm(HostPodVO pod); HostVO searchForAnotherRandomHostToStartSystemVm(VMInstanceVO vmInstance); AutonomiccsSystemVm deploySystemVmWithJava(Long hostId, SystemVmType systemVmType); @Override void afterPropertiesSet();  }
@Test public void getDefaultNetworkForAdvancedNetworkingWithSecurityGroupdsTest() { DataCenterVO dc = Mockito.mock(DataCenterVO.class); List<NetworkVO> networks = new ArrayList<>(); NetworkVO networkVo = Mockito.mock(NetworkVO.class); networks.add(networkVo); Mockito.doReturn(networks).when(networkDao).listByZoneSecurityGroup(Mockito.anyLong()); NetworkVO result = spy.getDefaultNetworkForAdvancedNetworkingWithSecurityGroupds(0l, dc); Mockito.verify(networkDao).listByZoneSecurityGroup(Mockito.anyLong()); Assert.assertEquals(networkVo, result); }
@Test(expected = CloudRuntimeException.class) public void getDefaultNetworkForAdvancedNetworkingWithSecurityGroupdsTestEmptyNetworkVoList() { DataCenterVO dc = Mockito.mock(DataCenterVO.class); Mockito.doReturn(new ArrayList<NetworkVO>()).when(networkDao).listByZoneSecurityGroup(Mockito.anyLong()); spy.getDefaultNetworkForAdvancedNetworkingWithSecurityGroupds(0l, dc); Mockito.verify(networkDao).listByZoneSecurityGroup(Mockito.anyLong()); }