Skip to content

Commit 18714f8

Browse files
committed
Add unit test for createTrafficTypeResponse
1 parent 5d7236d commit 18714f8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Diff for: server/src/test/java/com/cloud/api/ApiResponseHelperTest.java

+41
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.cloud.api;
1818

1919
import com.cloud.domain.DomainVO;
20+
import com.cloud.network.Networks;
21+
import com.cloud.network.PhysicalNetworkTrafficType;
2022
import com.cloud.network.as.AutoScaleVmGroup;
2123
import com.cloud.network.as.AutoScaleVmGroupVO;
2224
import com.cloud.network.as.AutoScaleVmProfileVO;
@@ -25,6 +27,9 @@
2527
import com.cloud.network.dao.LoadBalancerVO;
2628
import com.cloud.network.dao.NetworkServiceMapDao;
2729
import com.cloud.network.dao.NetworkVO;
30+
import com.cloud.network.dao.PhysicalNetworkVO;
31+
import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
32+
2833
import com.cloud.storage.VMTemplateVO;
2934
import com.cloud.usage.UsageVO;
3035
import com.cloud.user.Account;
@@ -43,6 +48,8 @@
4348
import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse;
4449
import org.apache.cloudstack.api.response.NicSecondaryIpResponse;
4550
import org.apache.cloudstack.api.response.UsageRecordResponse;
51+
import org.apache.cloudstack.api.response.TrafficTypeResponse;
52+
4653
import org.apache.cloudstack.context.CallContext;
4754
import org.apache.cloudstack.usage.UsageService;
4855
import org.junit.After;
@@ -66,6 +73,8 @@
6673
import static org.junit.Assert.assertEquals;
6774
import static org.junit.Assert.assertNull;
6875
import static org.junit.Assert.assertTrue;
76+
import static org.junit.Assert.assertFalse;
77+
6978
import static org.mockito.ArgumentMatchers.any;
7079
import static org.mockito.ArgumentMatchers.anyLong;
7180
import static org.mockito.Mockito.when;
@@ -367,4 +376,36 @@ public void testAutoScaleVmProfileResponseWithoutUserData() {
367376
assertNull(response.getUserDataDetails());
368377
}
369378
}
379+
380+
@Test
381+
public void testCreateTrafficTypeResponse() {
382+
PhysicalNetworkVO pnet = new PhysicalNetworkVO();
383+
pnet.addIsolationMethod("VXLAN");
384+
pnet.addIsolationMethod("STT");
385+
386+
try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) {
387+
when(ApiDBUtils.findPhysicalNetworkById(anyLong())).thenReturn(pnet);
388+
String xenLabel = "xen";
389+
String kvmLabel = "kvm";
390+
String vmwareLabel = "vmware";
391+
String simulatorLabel = "simulator";
392+
String hypervLabel = "hyperv";
393+
String ovmLabel = "ovm";
394+
String vlan = "vlan";
395+
String trafficType = "Public";
396+
PhysicalNetworkTrafficType pnetTrafficType = new PhysicalNetworkTrafficTypeVO(pnet.getId(), Networks.TrafficType.getTrafficType(trafficType), xenLabel, kvmLabel, vmwareLabel, simulatorLabel, vlan, hypervLabel, ovmLabel);
397+
398+
TrafficTypeResponse response = apiResponseHelper.createTrafficTypeResponse(pnetTrafficType);
399+
assertFalse(UUID.fromString(response.getId()).toString().isEmpty());
400+
assertEquals(response.getphysicalNetworkId(), pnet.getUuid());
401+
assertEquals(response.getTrafficType(), trafficType);
402+
assertEquals(response.getXenLabel(), xenLabel);
403+
assertEquals(response.getKvmLabel(), kvmLabel);
404+
assertEquals(response.getVmwareLabel(), vmwareLabel);
405+
assertEquals(response.getHypervLabel(), hypervLabel);
406+
assertEquals(response.getOvm3Label(), ovmLabel);
407+
assertEquals(response.getVlan(), vlan);
408+
assertEquals(response.getIsolationMethods(), "VXLAN,STT");
409+
}
410+
}
370411
}

0 commit comments

Comments
 (0)