Github user ProjectMoon commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1360#discussion_r58852188 --- Diff: server/test/com/cloud/consoleproxy/ConsoleProxyManagerTest.java --- @@ -87,4 +114,136 @@ public void testExisingCPVMStartFailure() throws Exception { cpvmManager.expandPool(new Long(1), new Object()); } + + @Test + public void getDefaultNetworkForAdvancedNonSG() { + DataCenterVO dc = mock(DataCenterVO.class); + when(dc.getNetworkType()).thenReturn(NetworkType.Advanced); + when(dc.isSecurityGroupEnabled()).thenReturn(false); + + when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc); + + NetworkVO network = Mockito.mock(NetworkVO.class); + NetworkVO badNetwork = Mockito.mock(NetworkVO.class); + when(_networkDao.listByZoneAndTrafficType(anyLong(), eq(TrafficType.Public))) + .thenReturn(Collections.singletonList(network)); + + when(_networkDao.listByZoneAndTrafficType(anyLong(), not(eq(TrafficType.Public)))) + .thenReturn(Collections.singletonList(badNetwork)); + + when(_networkDao.listByZoneSecurityGroup(anyLong())) + .thenReturn(Collections.singletonList(badNetwork)); + + NetworkVO returnedNetwork = cpvmManager.getDefaultNetworkForAdvancedZone(dc); + + Assert.assertNotNull(returnedNetwork); + Assert.assertEquals(network, returnedNetwork); + Assert.assertNotEquals(badNetwork, returnedNetwork); + } + + @Test + public void getDefaultNetworkForAdvancedSG() { --- End diff -- To cover all scenarios. Even if there is no security group-related checks in `getDefaultNetworkForBasicZone`, client code doesn't necessarily know this and the unit tests should make sure all possible combinations work.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---