2323import com .vmware .nsx .model .ClusterStatus ;
2424import com .vmware .nsx .model .ControllerClusterStatus ;
2525import com .vmware .nsx_policy .Infra ;
26+ import com .vmware .nsx_policy .InfraStub ;
2627import com .vmware .nsx_policy .infra .IpDiscoveryProfiles ;
2728import com .vmware .nsx_policy .infra .LbAppProfiles ;
2829import com .vmware .nsx_policy .infra .LbMonitorProfiles ;
5253import com .vmware .nsx_policy .model .SegmentDiscoveryProfileBindingMap ;
5354import com .vmware .nsx_policy .model .SegmentSecurityProfile ;
5455import com .vmware .vapi .bindings .Service ;
56+ import com .vmware .vapi .bindings .StubConfiguration ;
5557import com .vmware .vapi .bindings .Structure ;
58+ import com .vmware .vapi .core .ApiProvider ;
59+ import com .vmware .vapi .core .AsyncHandle ;
60+ import com .vmware .vapi .core .MethodResult ;
61+ import com .vmware .vapi .data .DataValue ;
5662import com .vmware .vapi .std .errors .Error ;
5763import com .vmware .vapi .std .errors .NotFound ;
5864import org .apache .cloudstack .resource .NsxLoadBalancerMember ;
@@ -118,7 +124,8 @@ public void testCreateGroupForSegment() {
118124
119125 @ Test
120126 public void testCreateSegmentBindsConfiguredProfiles () {
121- Infra infraService = Mockito .mock (Infra .class );
127+ ApiProvider apiProvider = Mockito .mock (ApiProvider .class );
128+ Infra infraService = Mockito .spy (new InfraStub (apiProvider , new StubConfiguration ()));
122129 IpDiscoveryProfiles ipProfiles = Mockito .mock (IpDiscoveryProfiles .class );
123130 MacDiscoveryProfiles macProfiles = Mockito .mock (MacDiscoveryProfiles .class );
124131 SegmentSecurityProfiles securityProfiles = Mockito .mock (SegmentSecurityProfiles .class );
@@ -138,6 +145,11 @@ public void testCreateSegmentBindsConfiguredProfiles() {
138145 when (ipProfile .getPath ()).thenReturn ("/infra/ip-discovery-profiles/ip-profile" );
139146 when (macProfile .getPath ()).thenReturn ("/infra/mac-discovery-profiles/mac-profile" );
140147 when (securityProfile .getPath ()).thenReturn ("/infra/segment-security-profiles/security-profile" );
148+ Mockito .doAnswer (invocation -> {
149+ AsyncHandle <MethodResult > asyncHandle = invocation .getArgument (4 );
150+ asyncHandle .setResult (MethodResult .EMPTY );
151+ return null ;
152+ }).when (apiProvider ).invoke (anyString (), eq ("patch" ), any (DataValue .class ), any (), any ());
141153 ArgumentCaptor <com .vmware .nsx_policy .model .Infra > infraCaptor =
142154 ArgumentCaptor .forClass (com .vmware .nsx_policy .model .Infra .class );
143155
@@ -146,6 +158,7 @@ public void testCreateSegmentBindsConfiguredProfiles() {
146158 "ip-profile" , "mac-profile" , "security-profile" );
147159
148160 verify (infraService ).patch (infraCaptor .capture (), eq (false ));
161+ verify (apiProvider ).invoke (anyString (), eq ("patch" ), any (DataValue .class ), any (), any ());
149162 verify (nsxService , never ()).apply (Segments .class );
150163 Assert .assertEquals ("Infra" , infraCaptor .getValue ().getResourceType ());
151164 Assert .assertEquals (1 , infraCaptor .getValue ().getChildren ().size ());
0 commit comments