Skip to content

Commit 0960ca0

Browse files
committed
Added UT for createVpcGuestNetwork
1 parent 1b63881 commit 0960ca0

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
17901790

17911791
if (vpcId != null && VpcManager.VpcTierNamePrepend.value()) {
17921792
final String connector = VpcManager.VpcTierNamePrependDelimiter.value();
1793-
Vpc vpc = _vpcDao.findById(vpcId);
1793+
Vpc vpc = _vpcDao.findById(vpcId);
17941794
if (vpc == null) {
17951795
throw new CloudRuntimeException(String.format("VPC with id %s not found", vpcId));
17961796
}

server/src/test/java/com/cloud/network/NetworkServiceImplTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,41 @@ public void testCreateIpv4RoutedNetwork() throws InsufficientCapacityException,
777777
Mockito.verify(routedIpv4Manager).assignIpv4SubnetToNetwork(nullable(Network.class));
778778
}
779779

780+
@Test
781+
public void testCreateVpcTier() throws InsufficientCapacityException, ResourceAllocationException, NoSuchFieldException, IllegalAccessException {
782+
Integer privateMtu = 1200;
783+
Long networkOfferingId = 1L;
784+
Long vpcId = 2L;
785+
786+
ReflectionTestUtils.setField(createNetworkCmd, "name", "testNetwork");
787+
ReflectionTestUtils.setField(createNetworkCmd, "displayText", "Test Network");
788+
ReflectionTestUtils.setField(createNetworkCmd, "networkOfferingId", networkOfferingId);
789+
ReflectionTestUtils.setField(createNetworkCmd, "zoneId", zoneId);
790+
ReflectionTestUtils.setField(createNetworkCmd, "privateMtu", privateMtu);
791+
ReflectionTestUtils.setField(createNetworkCmd, "vpcId", vpcId);
792+
793+
dc = Mockito.mock(DataCenterVO.class);
794+
Mockito.when(dcDao.findById(zoneId)).thenReturn(dc);
795+
Mockito.when(dc.getId()).thenReturn(zoneId);
796+
vpc = Mockito.mock(VpcVO.class);
797+
Mockito.when(vpc.getName()).thenReturn("Vpc 1");
798+
Mockito.when(vpcDao.findById(vpcId)).thenReturn(vpc);
799+
networkOfferingVO = Mockito.mock(NetworkOfferingVO.class);
800+
Mockito.when(networkOfferingDao.findById(networkOfferingId)).thenReturn(networkOfferingVO);
801+
Mockito.when(configMgr.isOfferingForVpc(networkOfferingVO)).thenReturn(true);
802+
803+
overrideDefaultConfigValue(VpcManager.VpcTierNamePrepend, "_defaultValue", "true");
804+
overrideDefaultConfigValue(VpcManager.VpcTierNamePrependDelimiter, "_defaultValue", " -- ");
805+
806+
service.createGuestNetwork(createNetworkCmd);
807+
808+
overrideDefaultConfigValue(VpcManager.VpcTierNamePrepend, "_defaultValue", "false");
809+
810+
Mockito.verify(vpcMgr, times(1)).createVpcGuestNetwork(networkOfferingId, "Vpc 1 -- testNetwork", "Test Network", null, null,
811+
null, null, accountMock, null, phyNet, zoneId, null, null, vpcId, null, accountMock, true,
812+
null, null, null, null, null, null, null, new Pair<>(0, privateMtu), null);
813+
}
814+
780815
@Test
781816
public void testCheckAndUpdateNetworkResetSuccess() {
782817
NetworkVO networkVO = new NetworkVO();

0 commit comments

Comments
 (0)