1919import static org .mockito .ArgumentMatchers .any ;
2020import static org .mockito .ArgumentMatchers .anyLong ;
2121import static org .mockito .ArgumentMatchers .eq ;
22- import static org .mockito .ArgumentMatchers .isNull ;
2322import static org .mockito .ArgumentMatchers .nullable ;
2423import static org .mockito .Mockito .when ;
2524
2625import java .util .ArrayList ;
2726import java .util .UUID ;
2827
28+ import org .apache .cloudstack .api .ApiConstants ;
2929import org .apache .cloudstack .api .command .user .loadbalancer .UpdateLoadBalancerRuleCmd ;
3030import org .apache .cloudstack .context .CallContext ;
31+ import org .apache .cloudstack .resourcedetail .dao .FirewallRuleDetailsDao ;
3132import org .junit .After ;
3233import org .junit .Before ;
3334import org .junit .Test ;
3435import org .mockito .InOrder ;
3536import org .mockito .Mockito ;
37+ import org .springframework .test .util .ReflectionTestUtils ;
3638
3739import com .cloud .exception .InsufficientCapacityException ;
3840import com .cloud .exception .InvalidParameterValueException ;
@@ -70,6 +72,7 @@ public class UpdateLoadBalancerTest {
7072 private LoadBalancingServiceProvider lbServiceProvider = Mockito .mock (LoadBalancingServiceProvider .class );
7173
7274 private static long domainId = 5L ;
75+ private static long lbRuleId = 10L ;
7376 private static String accountName = "admin" ;
7477
7578 @ Before
@@ -83,11 +86,13 @@ public void setUp() {
8386 _lbMgr ._lb2stickinesspoliciesDao = Mockito .mock (LBStickinessPolicyDao .class );
8487 _lbMgr ._lb2VmMapDao = Mockito .mock (LoadBalancerVMMapDao .class );
8588 _lbMgr ._lbCertMapDao = Mockito .mock (LoadBalancerCertMapDao .class );
89+ _lbMgr ._firewallRuleDetailsDao = Mockito .mock (FirewallRuleDetailsDao .class );
8690 _lbMgr ._lbDao = lbDao ;
8791 _lbMgr ._lbProviders = new ArrayList <LoadBalancingServiceProvider >();
8892 _lbMgr ._lbProviders .add (lbServiceProvider );
8993
9094 updateLbRuleCmd = new UpdateLoadBalancerRuleCmd ();
95+ ReflectionTestUtils .setField (updateLbRuleCmd , ApiConstants .ID , lbRuleId );
9196
9297 AccountVO account = new AccountVO (accountName , domainId , "networkDomain" , Account .Type .NORMAL , "uuid" );
9398 UserVO user = new UserVO (1 , "testuser" , "password" , "firstname" , "lastName" , "email" , "timezone" , UUID .randomUUID ().toString (), User .Source .UNKNOWN );
@@ -99,26 +104,26 @@ public void testValidateRuleBeforeUpdateLB() throws ResourceAllocationException,
99104
100105 LoadBalancerVO lb = new LoadBalancerVO (null , null , null , 0L , 0 , 0 , null , 0L , 0L , domainId , null , null );
101106
102- when (lbDao .findById (isNull () )).thenReturn (lb );
107+ when (lbDao .findById (lbRuleId )).thenReturn (lb );
103108 when (netModel .getPublicIpAddress (anyLong ())).thenReturn (Mockito .mock (PublicIpAddress .class ));
104109 when (netDao .findById (anyLong ())).thenReturn (Mockito .mock (NetworkVO .class ));
105110 when (lbServiceProvider .validateLBRule (any (Network .class ), any (LoadBalancingRule .class ))).thenReturn (true );
106- when (lbDao .update (isNull ( ), eq (lb ))).thenReturn (true );
111+ when (lbDao .update (eq ( lbRuleId ), eq (lb ))).thenReturn (true );
107112 when (netDao .findById (nullable (Long .class ))).thenReturn (Mockito .mock (NetworkVO .class ));
108113 when (ntwkOffServiceMapDao .canProviderSupportServiceInNetworkOffering (nullable (Long .class ), any (Network .Service .class ), any (Network .Provider .class ))).thenReturn (false );
109114 _lbMgr .updateLoadBalancerRule (updateLbRuleCmd );
110115
111116 InOrder inOrder = Mockito .inOrder (lbServiceProvider , lbDao );
112117 inOrder .verify (lbServiceProvider ).validateLBRule (any (Network .class ), any (LoadBalancingRule .class ));
113- inOrder .verify (lbDao ).update (isNull (), eq (lb ));
118+ inOrder .verify (lbDao ).update (eq ( lbRuleId ), eq (lb ));
114119 }
115120
116121 @ Test (expected = InvalidParameterValueException .class )
117122 public void testRuleNotValidated () throws ResourceAllocationException , ResourceUnavailableException , InsufficientCapacityException {
118123
119124 LoadBalancerVO lb = new LoadBalancerVO (null , null , null , 0L , 0 , 0 , null , 0L , 0L , domainId , null , null );
120125
121- when (lbDao .findById (anyLong () )).thenReturn (lb );
126+ when (lbDao .findById (lbRuleId )).thenReturn (lb );
122127 when (netModel .getPublicIpAddress (anyLong ())).thenReturn (Mockito .mock (PublicIpAddress .class ));
123128 when (netDao .findById (anyLong ())).thenReturn (Mockito .mock (NetworkVO .class ));
124129 when (lbServiceProvider .validateLBRule (any (Network .class ), any (LoadBalancingRule .class ))).thenReturn (false );
0 commit comments