@@ -2572,37 +2572,9 @@ public void addInbuiltExtensionReservedResourceDetailsAddedDetails() {
25722572 }
25732573
25742574 // -----------------------------------------------------------------------
2575- // Tests for ExtensionHelper methods (external network device support)
2575+ // Tests for network custom action behavior
25762576 // -----------------------------------------------------------------------
25772577
2578- @ Test
2579- public void getExtensionForPhysicalNetworkReturnsExtensionWhenRegistered () {
2580- long physNetId = 10L ;
2581- long extensionId = 5L ;
2582- ExtensionResourceMapVO mapVO = mock (ExtensionResourceMapVO .class );
2583- when (mapVO .getExtensionId ()).thenReturn (extensionId );
2584- when (extensionResourceMapDao .listByResourceIdAndType (physNetId ,
2585- ExtensionResourceMap .ResourceType .PhysicalNetwork )).thenReturn (List .of (mapVO ));
2586- ExtensionVO ext = mock (ExtensionVO .class );
2587- when (extensionDao .findById (extensionId )).thenReturn (ext );
2588-
2589- Extension result = extensionsManager .getExtensionForPhysicalNetwork (physNetId );
2590-
2591- assertNotNull (result );
2592- assertEquals (ext , result );
2593- }
2594-
2595- @ Test
2596- public void getExtensionForPhysicalNetworkReturnsNullWhenNotRegistered () {
2597- long physNetId = 10L ;
2598- when (extensionResourceMapDao .listByResourceIdAndType (physNetId ,
2599- ExtensionResourceMap .ResourceType .PhysicalNetwork )).thenReturn (Collections .emptyList ());
2600-
2601- Extension result = extensionsManager .getExtensionForPhysicalNetwork (physNetId );
2602-
2603- assertNull (result );
2604- }
2605-
26062578
26072579 // Helper: a mock object that is both a NetworkElement and a NetworkCustomActionProvider
26082580 interface MockNetworkElement extends NetworkElement , NetworkCustomActionProvider {}
@@ -2684,8 +2656,8 @@ public void getExtensionFromResourceReturnsExtensionForNetworkWithProviderMatch(
26842656 when (network .getPhysicalNetworkId ()).thenReturn (5L );
26852657 when (entityManager .findByUuid (eq (Network .class ), eq ("net-uuid" ))).thenReturn (network );
26862658
2687- List < String > providers = List . of ( "my-ext-provider" ) ;
2688- when (networkServiceMapDao .getDistinctProviders (10L )).thenReturn (providers );
2659+ String providerName = "my-ext-provider" ;
2660+ when (networkServiceMapDao .getProviderForServiceInNetwork (10L , Network . Service . CustomAction )).thenReturn (providerName );
26892661
26902662 ExtensionVO ext = mock (ExtensionVO .class );
26912663 doReturn (ext ).when (extensionsManager ).getExtensionForPhysicalNetworkAndProvider (5L , "my-ext-provider" );
@@ -2723,6 +2695,54 @@ public void getExtensionFromResourceReturnsNullForNetworkWithNullPhysicalNetwork
27232695 assertNull (result );
27242696 }
27252697
2698+ // -----------------------------------------------------------------------
2699+ // Tests for getExtensionFromResource with Vpc resource type
2700+ // -----------------------------------------------------------------------
2701+
2702+ @ Test
2703+ public void getExtensionFromResourceReturnsExtensionForVpcWithProviderMatch () {
2704+ Vpc vpc = mock (Vpc .class );
2705+ when (vpc .getId ()).thenReturn (20L );
2706+ when (entityManager .findByUuid (eq (Vpc .class ), eq ("vpc-uuid" ))).thenReturn (vpc );
2707+
2708+ when (vpcServiceMapDao .getProviderForServiceInVpc (20L , Network .Service .CustomAction )).thenReturn ("my-vpc-provider" );
2709+
2710+ ExtensionVO ext = mock (ExtensionVO .class );
2711+ when (extensionDao .findByName ("my-vpc-provider" )).thenReturn (ext );
2712+
2713+ Extension result = extensionsManager .getExtensionFromResource (ExtensionCustomAction .ResourceType .Vpc , "vpc-uuid" );
2714+
2715+ assertEquals (ext , result );
2716+ }
2717+
2718+ @ Test
2719+ public void getExtensionFromResourceReturnsNullForVpcWithoutProvider () {
2720+ Vpc vpc = mock (Vpc .class );
2721+ when (vpc .getId ()).thenReturn (20L );
2722+ when (entityManager .findByUuid (eq (Vpc .class ), eq ("vpc-uuid" ))).thenReturn (vpc );
2723+
2724+ when (vpcServiceMapDao .getProviderForServiceInVpc (20L , Network .Service .CustomAction )).thenReturn (null );
2725+
2726+ Extension result = extensionsManager .getExtensionFromResource (ExtensionCustomAction .ResourceType .Vpc , "vpc-uuid" );
2727+
2728+ assertNull (result );
2729+ verify (extensionDao , never ()).findByName (anyString ());
2730+ }
2731+
2732+ @ Test
2733+ public void getExtensionFromResourceReturnsNullForVpcWhenProviderExtensionNotFound () {
2734+ Vpc vpc = mock (Vpc .class );
2735+ when (vpc .getId ()).thenReturn (20L );
2736+ when (entityManager .findByUuid (eq (Vpc .class ), eq ("vpc-uuid" ))).thenReturn (vpc );
2737+
2738+ when (vpcServiceMapDao .getProviderForServiceInVpc (20L , Network .Service .CustomAction )).thenReturn ("missing-provider" );
2739+ when (extensionDao .findByName ("missing-provider" )).thenReturn (null );
2740+
2741+ Extension result = extensionsManager .getExtensionFromResource (ExtensionCustomAction .ResourceType .Vpc , "vpc-uuid" );
2742+
2743+ assertNull (result );
2744+ }
2745+
27262746 // -----------------------------------------------------------------------
27272747 // Tests for listExtensions with resourceId + resourceType (PhysicalNetwork)
27282748 // -----------------------------------------------------------------------
@@ -2825,29 +2845,6 @@ public void registerExtensionWithPhysicalNetworkFailsForNonNetworkOrchestratorTy
28252845 extensionsManager .registerExtensionWithResource (cmd );
28262846 }
28272847
2828- // -----------------------------------------------------------------------
2829- // Tests for getExtensionIdForPhysicalNetwork
2830- // -----------------------------------------------------------------------
2831-
2832- @ Test
2833- public void getExtensionIdForPhysicalNetworkReturnsIdWhenMapped () {
2834- ExtensionResourceMapVO mapVO = mock (ExtensionResourceMapVO .class );
2835- when (mapVO .getExtensionId ()).thenReturn (55L );
2836- when (extensionResourceMapDao .listByResourceIdAndType (10L , ExtensionResourceMap .ResourceType .PhysicalNetwork ))
2837- .thenReturn (List .of (mapVO ));
2838-
2839- Long result = extensionsManager .getExtensionIdForPhysicalNetwork (10L );
2840- assertEquals (Long .valueOf (55L ), result );
2841- }
2842-
2843- @ Test
2844- public void getExtensionIdForPhysicalNetworkReturnsNullWhenNotMapped () {
2845- when (extensionResourceMapDao .listByResourceIdAndType (10L , ExtensionResourceMap .ResourceType .PhysicalNetwork ))
2846- .thenReturn (Collections .emptyList ());
2847-
2848- Long result = extensionsManager .getExtensionIdForPhysicalNetwork (10L );
2849- assertNull (result );
2850- }
28512848
28522849 // -----------------------------------------------------------------------
28532850 // Tests for getExtensionForPhysicalNetworkAndProvider
0 commit comments