Github user borisroman commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/887#discussion_r40445748
  
    --- 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's better to not have the try catch structure in a test. If a test throws 
an exceptions it will automatically be handled as failure.


---
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.
---

Reply via email to