Github user borisroman commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/887#discussion_r40450212 --- Diff: server/test/com/cloud/network/firewall/FirewallManagerTest.java --- @@ -151,4 +182,38 @@ public void testApplyFWRules() { } } + @Test + public void testDetectRulesConflict() { + List<FirewallRuleVO> ruleList = new ArrayList<FirewallRuleVO>(); + FirewallRuleVO rule1 = spy(new FirewallRuleVO("rule1", 3, 500, "UDP", 1, 2, 1, Purpose.Vpn, null, null, null, null)); + FirewallRuleVO rule2 = spy(new FirewallRuleVO("rule2", 3, 1701, "UDP", 1, 2, 1, Purpose.Vpn, null, null, null, null)); + FirewallRuleVO rule3 = spy(new FirewallRuleVO("rule3", 3, 4500, "UDP", 1, 2, 1, Purpose.Vpn, null, null, null, null)); + + ruleList.add(rule1); + ruleList.add(rule2); + ruleList.add(rule3); + + FirewallManagerImpl firewallMgr = (FirewallManagerImpl)_firewallMgr; + + when(firewallMgr._firewallDao.listByIpAndPurposeAndNotRevoked(3,null)).thenReturn(ruleList); + when(rule1.getId()).thenReturn(1L); + when(rule2.getId()).thenReturn(2L); + when(rule3.getId()).thenReturn(3L); + + FirewallRule newRule1 = new FirewallRuleVO("newRule1", 3, 500, "TCP", 1, 2, 1, Purpose.PortForwarding, null, null, null, null); + FirewallRule newRule2 = new FirewallRuleVO("newRule2", 3, 1701, "TCP", 1, 2, 1, Purpose.PortForwarding, null, null, null, null); + FirewallRule newRule3 = new FirewallRuleVO("newRule3", 3, 4500, "TCP", 1, 2, 1, Purpose.PortForwarding, null, null, null, null); + + try { + firewallMgr.detectRulesConflict(newRule1); + firewallMgr.detectRulesConflict(newRule2); + firewallMgr.detectRulesConflict(newRule3); + } + catch (NetworkRuleConflictException ex) { + Assert.fail(); --- End diff -- It is syntactically correct. Though this way you remove the error message from the test failure. It just fails because it hits a fail(). If the exception is thrown without the try catch then if the test fails it will show why.
--- 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. ---