@@ -782,89 +782,38 @@ public void testCreateIpv4RoutedNetwork() {
782782 }
783783
784784 @ Test
785- public void testCreateIpv4RoutedNetworkWithBgpPeersFailure1 () {
786- registerCallContext ();
787- CreateNetworkCmdByAdmin cmd = Mockito .mock (CreateNetworkCmdByAdmin .class );
788- Mockito .when (cmd .getCidrSize ()).thenReturn (24 );
789- List <Long > bgpPeerIds = Arrays .asList (11L , 12L );
790- Mockito .when (cmd .getBgpPeerIds ()).thenReturn (bgpPeerIds );
791-
792- prepareCreateNetworkDnsMocks (cmd , Network .GuestType .Isolated , false , true , true );
793- when (networkOfferingVO .getNetworkMode ()).thenReturn (NetworkOffering .NetworkMode .ROUTED );
794- when (networkOfferingVO .getRoutingMode ()).thenReturn (NetworkOffering .RoutingMode .Static );
795- when (routedIpv4Manager .isRoutedNetworkVpcEnabled (nullable (Long .class ))).thenReturn (true );
796- when (routedIpv4Manager .isVirtualRouterGateway (networkOfferingVO )).thenReturn (true );
797-
798- DataCenterVO zone = Mockito .mock (DataCenterVO .class );
799- when (cmd .getZoneId ()).thenReturn (zoneId );
800- when (dcDao .findById (zoneId )).thenReturn (zone );
801- when (zone .getId ()).thenReturn (zoneId );
802-
803- try {
804- service .createGuestNetwork (cmd );
805- } catch (InsufficientCapacityException | ResourceAllocationException e ) {
806- Assert .fail (String .format ("failure with exception: %s" , e .getMessage ()));
807- } catch (InvalidParameterValueException ex ) {
808- Assert .assertEquals ("The BGP peers of VPC tiers will inherit from the VPC, do not add separately." , ex .getMessage ());
809- }
810- }
811-
812- @ Test
813- public void testCreateIpv4RoutedNetworkWithBgpPeersFailure2 () {
814- registerCallContext ();
815- CreateNetworkCmdByAdmin cmd = Mockito .mock (CreateNetworkCmdByAdmin .class );
816- Mockito .when (cmd .getCidrSize ()).thenReturn (24 );
817- List <Long > bgpPeerIds = Arrays .asList (11L , 12L );
818- Mockito .when (cmd .getBgpPeerIds ()).thenReturn (bgpPeerIds );
819-
820- prepareCreateNetworkDnsMocks (cmd , Network .GuestType .Isolated , false , false , true );
821- when (networkOfferingVO .getNetworkMode ()).thenReturn (NetworkOffering .NetworkMode .ROUTED );
822- when (networkOfferingVO .getRoutingMode ()).thenReturn (NetworkOffering .RoutingMode .Static );
823- when (routedIpv4Manager .isRoutedNetworkVpcEnabled (nullable (Long .class ))).thenReturn (true );
824- when (routedIpv4Manager .isVirtualRouterGateway (networkOfferingVO )).thenReturn (true );
785+ public void testCreateVpcTier () throws InsufficientCapacityException , ResourceAllocationException , NoSuchFieldException , IllegalAccessException {
786+ Integer privateMtu = 1200 ;
787+ Long networkOfferingId = 1L ;
788+ Long vpcId = 2L ;
825789
826- DataCenterVO zone = Mockito .mock (DataCenterVO .class );
827- when (cmd .getZoneId ()).thenReturn (zoneId );
828- when (dcDao .findById (zoneId )).thenReturn (zone );
829- when (zone .getId ()).thenReturn (zoneId );
790+ ReflectionTestUtils .setField (createNetworkCmd , "name" , "testNetwork" );
791+ ReflectionTestUtils .setField (createNetworkCmd , "displayText" , "Test Network" );
792+ ReflectionTestUtils .setField (createNetworkCmd , "networkOfferingId" , networkOfferingId );
793+ ReflectionTestUtils .setField (createNetworkCmd , "zoneId" , zoneId );
794+ ReflectionTestUtils .setField (createNetworkCmd , "privateMtu" , privateMtu );
795+ ReflectionTestUtils .setField (createNetworkCmd , "vpcId" , vpcId );
830796
831- try {
832- service .createGuestNetwork (cmd );
833- } catch (InsufficientCapacityException | ResourceAllocationException e ) {
834- Assert .fail (String .format ("failure with exception: %s" , e .getMessage ()));
835- } catch (InvalidParameterValueException ex ) {
836- Assert .assertEquals ("The network offering does not support Dynamic routing" , ex .getMessage ());
837- }
838- }
797+ dc = Mockito .mock (DataCenterVO .class );
798+ Mockito .when (dcDao .findById (zoneId )).thenReturn (dc );
799+ Mockito .when (dc .getId ()).thenReturn (zoneId );
800+ vpc = Mockito .mock (VpcVO .class );
801+ Mockito .when (vpc .getName ()).thenReturn ("Vpc 1" );
802+ Mockito .when (vpcDao .findById (vpcId )).thenReturn (vpc );
803+ networkOfferingVO = Mockito .mock (NetworkOfferingVO .class );
804+ Mockito .when (networkOfferingDao .findById (networkOfferingId )).thenReturn (networkOfferingVO );
805+ Mockito .when (configMgr .isOfferingForVpc (networkOfferingVO )).thenReturn (true );
839806
840- @ Test
841- public void testCreateIpv4RoutedNetworkWithBgpPeersFailure3 () {
842- registerCallContext ();
843- CreateNetworkCmdByAdmin cmd = Mockito .mock (CreateNetworkCmdByAdmin .class );
844- Mockito .when (cmd .getCidrSize ()).thenReturn (24 );
845- List <Long > bgpPeerIds = Arrays .asList (11L , 12L );
846- Mockito .when (cmd .getBgpPeerIds ()).thenReturn (bgpPeerIds );
807+ overrideDefaultConfigValue (VpcManager .VpcTierNamePrepend , "_defaultValue" , "true" );
808+ overrideDefaultConfigValue (VpcManager .VpcTierNamePrependDelimiter , "_defaultValue" , " -- " );
847809
848- prepareCreateNetworkDnsMocks (cmd , Network .GuestType .Isolated , false , false , true );
849- when (networkOfferingVO .getNetworkMode ()).thenReturn (NetworkOffering .NetworkMode .ROUTED );
850- when (networkOfferingVO .getRoutingMode ()).thenReturn (NetworkOffering .RoutingMode .Static );
851- when (routedIpv4Manager .isRoutedNetworkVpcEnabled (nullable (Long .class ))).thenReturn (true );
852- when (routedIpv4Manager .isVirtualRouterGateway (networkOfferingVO )).thenReturn (true );
853- when (routedIpv4Manager .isDynamicRoutedNetwork (networkOfferingVO )).thenReturn (true );
854- doThrow (new InvalidParameterValueException ("validation error" )).when (routedIpv4Manager ).validateBgpPeers (nullable (Account .class ), nullable (Long .class ), any (List .class ));
810+ service .createGuestNetwork (createNetworkCmd );
855811
856- DataCenterVO zone = Mockito .mock (DataCenterVO .class );
857- when (cmd .getZoneId ()).thenReturn (zoneId );
858- when (dcDao .findById (zoneId )).thenReturn (zone );
859- when (zone .getId ()).thenReturn (zoneId );
812+ overrideDefaultConfigValue (VpcManager .VpcTierNamePrepend , "_defaultValue" , "false" );
860813
861- try {
862- service .createGuestNetwork (cmd );
863- } catch (InsufficientCapacityException | ResourceAllocationException e ) {
864- Assert .fail (String .format ("failure with exception: %s" , e .getMessage ()));
865- } catch (InvalidParameterValueException ex ) {
866- Assert .assertEquals ("validation error" , ex .getMessage ());
867- }
814+ Mockito .verify (vpcMgr , times (1 )).createVpcGuestNetwork (networkOfferingId , "Vpc 1 -- testNetwork" , "Test Network" , null , null ,
815+ null , null , accountMock , null , phyNet , zoneId , null , null , vpcId , null , accountMock , true ,
816+ null , null , null , null , null , null , null , new Pair <>(0 , privateMtu ), null );
868817 }
869818
870819 @ Test
0 commit comments