|
16 | 16 | // under the License. |
17 | 17 | package com.cloud.api; |
18 | 18 |
|
19 | | -import static org.junit.Assert.assertEquals; |
20 | | -import static org.junit.Assert.assertNull; |
21 | | -import static org.junit.Assert.assertTrue; |
22 | | -import static org.mockito.ArgumentMatchers.any; |
23 | | -import static org.mockito.ArgumentMatchers.anyLong; |
24 | | -import static org.mockito.Mockito.verify; |
25 | | -import static org.mockito.Mockito.when; |
26 | | - |
27 | 19 | import java.lang.reflect.Field; |
28 | 20 | import java.text.ParseException; |
29 | 21 | import java.text.SimpleDateFormat; |
|
37 | 29 | import java.util.TimeZone; |
38 | 30 | import java.util.UUID; |
39 | 31 |
|
| 32 | +import org.junit.After; |
| 33 | +import org.junit.Assert; |
| 34 | +import org.junit.Before; |
| 35 | +import org.junit.Test; |
| 36 | +import org.junit.runner.RunWith; |
| 37 | +import org.mockito.InjectMocks; |
| 38 | +import org.mockito.Mock; |
| 39 | +import org.mockito.MockedStatic; |
| 40 | +import org.mockito.Mockito; |
| 41 | +import org.mockito.Spy; |
| 42 | +import org.mockito.junit.MockitoJUnitRunner; |
| 43 | +import org.springframework.test.util.ReflectionTestUtils; |
| 44 | + |
40 | 45 | import org.apache.cloudstack.annotation.dao.AnnotationDao; |
| 46 | +import org.apache.cloudstack.api.ResponseObject; |
41 | 47 | import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse; |
42 | 48 | import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse; |
| 49 | +import org.apache.cloudstack.api.response.ConsoleSessionResponse; |
43 | 50 | import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse; |
44 | 51 | import org.apache.cloudstack.api.response.GuestOSCategoryResponse; |
45 | 52 | import org.apache.cloudstack.api.response.IpQuarantineResponse; |
|
48 | 55 | import org.apache.cloudstack.api.response.TemplateResponse; |
49 | 56 | import org.apache.cloudstack.api.response.UnmanagedInstanceResponse; |
50 | 57 | import org.apache.cloudstack.api.response.UsageRecordResponse; |
| 58 | +import org.apache.cloudstack.api.response.TrafficTypeResponse; |
51 | 59 | import org.apache.cloudstack.context.CallContext; |
52 | 60 | import org.apache.cloudstack.usage.UsageService; |
53 | 61 | import org.apache.cloudstack.vm.UnmanagedInstanceTO; |
54 | | -import org.junit.After; |
55 | | -import org.junit.Assert; |
56 | | -import org.junit.Before; |
57 | | -import org.junit.Test; |
58 | | -import org.junit.runner.RunWith; |
59 | | -import org.mockito.InjectMocks; |
60 | | -import org.mockito.Mock; |
61 | | -import org.mockito.MockedStatic; |
62 | | -import org.mockito.Mockito; |
63 | | -import org.mockito.Spy; |
64 | | -import org.mockito.junit.MockitoJUnitRunner; |
65 | | -import org.springframework.test.util.ReflectionTestUtils; |
66 | 62 |
|
67 | 63 | import com.cloud.capacity.Capacity; |
68 | 64 | import com.cloud.configuration.Resource; |
69 | 65 | import com.cloud.domain.DomainVO; |
70 | 66 | import com.cloud.host.HostVO; |
| 67 | +import com.cloud.network.Networks; |
| 68 | +import com.cloud.network.PhysicalNetworkTrafficType; |
71 | 69 | import com.cloud.network.PublicIpQuarantine; |
72 | 70 | import com.cloud.network.as.AutoScaleVmGroup; |
73 | 71 | import com.cloud.network.as.AutoScaleVmGroupVO; |
|
78 | 76 | import com.cloud.network.dao.LoadBalancerVO; |
79 | 77 | import com.cloud.network.dao.NetworkServiceMapDao; |
80 | 78 | import com.cloud.network.dao.NetworkVO; |
| 79 | +import com.cloud.network.dao.PhysicalNetworkVO; |
| 80 | +import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; |
81 | 81 | import com.cloud.resource.icon.ResourceIconVO; |
82 | 82 | import com.cloud.server.ResourceIcon; |
83 | 83 | import com.cloud.server.ResourceIconManager; |
|
97 | 97 | import com.cloud.vm.ConsoleSessionVO; |
98 | 98 | import com.cloud.vm.NicSecondaryIp; |
99 | 99 | import com.cloud.vm.VMInstanceVO; |
100 | | -import org.apache.cloudstack.api.ResponseObject; |
101 | | -import org.apache.cloudstack.api.response.ConsoleSessionResponse; |
| 100 | + |
| 101 | +import static org.junit.Assert.assertEquals; |
| 102 | +import static org.junit.Assert.assertFalse; |
| 103 | +import static org.junit.Assert.assertNull; |
| 104 | +import static org.junit.Assert.assertTrue; |
| 105 | +import static org.mockito.ArgumentMatchers.any; |
| 106 | +import static org.mockito.ArgumentMatchers.anyLong; |
| 107 | +import static org.mockito.Mockito.verify; |
| 108 | +import static org.mockito.Mockito.when; |
| 109 | + |
102 | 110 |
|
103 | 111 | @RunWith(MockitoJUnitRunner.class) |
104 | 112 | public class ApiResponseHelperTest { |
@@ -417,6 +425,39 @@ public void testAutoScaleVmProfileResponseWithoutUserData() { |
417 | 425 | } |
418 | 426 | } |
419 | 427 |
|
| 428 | + @Test |
| 429 | + public void testCreateTrafficTypeResponse() { |
| 430 | + PhysicalNetworkVO pnet = new PhysicalNetworkVO(); |
| 431 | + pnet.addIsolationMethod("VXLAN"); |
| 432 | + pnet.addIsolationMethod("STT"); |
| 433 | + |
| 434 | + try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) { |
| 435 | + when(ApiDBUtils.findPhysicalNetworkById(anyLong())).thenReturn(pnet); |
| 436 | + String xenLabel = "xen"; |
| 437 | + String kvmLabel = "kvm"; |
| 438 | + String vmwareLabel = "vmware"; |
| 439 | + String simulatorLabel = "simulator"; |
| 440 | + String hypervLabel = "hyperv"; |
| 441 | + String ovmLabel = "ovm"; |
| 442 | + String vlan = "vlan"; |
| 443 | + String trafficType = "Public"; |
| 444 | + PhysicalNetworkTrafficType pnetTrafficType = new PhysicalNetworkTrafficTypeVO(pnet.getId(), Networks.TrafficType.getTrafficType(trafficType), xenLabel, kvmLabel, vmwareLabel, simulatorLabel, vlan, hypervLabel, ovmLabel); |
| 445 | + |
| 446 | + TrafficTypeResponse response = apiResponseHelper.createTrafficTypeResponse(pnetTrafficType); |
| 447 | + assertFalse(UUID.fromString(response.getId()).toString().isEmpty()); |
| 448 | + assertEquals(response.getphysicalNetworkId(), pnet.getUuid()); |
| 449 | + assertEquals(response.getTrafficType(), trafficType); |
| 450 | + assertEquals(response.getXenLabel(), xenLabel); |
| 451 | + assertEquals(response.getKvmLabel(), kvmLabel); |
| 452 | + assertEquals(response.getVmwareLabel(), vmwareLabel); |
| 453 | + assertEquals(response.getHypervLabel(), hypervLabel); |
| 454 | + assertEquals(response.getOvm3Label(), ovmLabel); |
| 455 | + assertEquals(response.getVlan(), vlan); |
| 456 | + assertEquals(response.getIsolationMethods(), "VXLAN,STT"); |
| 457 | + |
| 458 | + } |
| 459 | + } |
| 460 | + |
420 | 461 | private UnmanagedInstanceTO getUnmanagedInstaceForTests() { |
421 | 462 | UnmanagedInstanceTO instance = Mockito.mock(UnmanagedInstanceTO.class); |
422 | 463 | Mockito.when(instance.getPowerState()).thenReturn(UnmanagedInstanceTO.PowerState.PowerOff); |
|
0 commit comments