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

    https://github.com/apache/cloudstack/pull/887#discussion_r40449738
  
    --- 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 --
    
    Although I did not write it, I would say that if the exception happens, and 
was not expected, the test should fail, as the code does it. Another way to do 
this would be to expect the exception and check if the exception thrown is the 
one expected, then the test would pass, given the expectation.
    
    Given the code above, it's okay to fail it. It's like the person who wrote 
is saying: if an exception happens, then fail it.


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