|
49 | 49 | import org.apache.cloudstack.api.response.ConsoleSessionResponse; |
50 | 50 | import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse; |
51 | 51 | import org.apache.cloudstack.api.response.GuestOSCategoryResponse; |
| 52 | +import org.apache.cloudstack.api.response.IPAddressResponse; |
52 | 53 | import org.apache.cloudstack.api.response.IpQuarantineResponse; |
53 | 54 | import org.apache.cloudstack.api.response.NicSecondaryIpResponse; |
54 | 55 | import org.apache.cloudstack.api.response.ResourceIconResponse; |
|
64 | 65 | import com.cloud.configuration.Resource; |
65 | 66 | import com.cloud.domain.DomainVO; |
66 | 67 | import com.cloud.host.HostVO; |
| 68 | +import com.cloud.network.IpAddress; |
67 | 69 | import com.cloud.network.Networks; |
68 | 70 | import com.cloud.network.PhysicalNetworkTrafficType; |
69 | 71 | import com.cloud.network.PublicIpQuarantine; |
|
96 | 98 | import com.cloud.utils.net.Ip; |
97 | 99 | import com.cloud.vm.ConsoleSessionVO; |
98 | 100 | import com.cloud.vm.NicSecondaryIp; |
| 101 | +import com.cloud.vm.NicVO; |
99 | 102 | import com.cloud.vm.VMInstanceVO; |
| 103 | +import com.cloud.vm.VirtualMachine; |
100 | 104 |
|
101 | 105 | import static org.junit.Assert.assertEquals; |
102 | 106 | import static org.junit.Assert.assertFalse; |
@@ -800,4 +804,28 @@ public void createConsoleSessionResponseTestShouldReturnFullResponse() { |
800 | 804 | Assert.assertEquals(expected.getVmName(), response.getVmName()); |
801 | 805 | } |
802 | 806 | } |
| 807 | + |
| 808 | + @Test |
| 809 | + public void showVmInfoForSharedNetworksTestSkipsPlaceHolderNic() { |
| 810 | + IpAddress ipAddress = Mockito.mock(IpAddress.class); |
| 811 | + Mockito.when(ipAddress.getAddress()).thenReturn(new Ip("10.1.1.10")); |
| 812 | + Mockito.when(ipAddress.getNetworkId()).thenReturn(1L); |
| 813 | + NicVO nic = Mockito.mock(NicVO.class); |
| 814 | + Mockito.when(nic.getVmType()).thenReturn(VirtualMachine.Type.DomainRouter); |
| 815 | + Mockito.when(nic.getInstanceId()).thenReturn(2L); |
| 816 | + Mockito.when(vmInstanceVOMock.getUuid()).thenReturn("router-uuid"); |
| 817 | + Mockito.when(vmInstanceVOMock.getHostName()).thenReturn("r-2-VM"); |
| 818 | + Mockito.when(vmInstanceVOMock.getType()).thenReturn(VirtualMachine.Type.DomainRouter); |
| 819 | + IPAddressResponse response = new IPAddressResponse(); |
| 820 | + |
| 821 | + try (MockedStatic<ApiDBUtils> apiDBUtilsStaticMock = Mockito.mockStatic(ApiDBUtils.class)) { |
| 822 | + apiDBUtilsStaticMock.when(() -> ApiDBUtils.findNonPlaceHolderByIp4AddressAndNetworkId("10.1.1.10", 1L)).thenReturn(nic); |
| 823 | + apiDBUtilsStaticMock.when(() -> ApiDBUtils.findVMInstanceById(2L)).thenReturn(vmInstanceVOMock); |
| 824 | + |
| 825 | + ReflectionTestUtils.invokeMethod(apiResponseHelper, "showVmInfoForSharedNetworks", false, ipAddress, response); |
| 826 | + |
| 827 | + apiDBUtilsStaticMock.verify(() -> ApiDBUtils.findByIp4AddressAndNetworkId(Mockito.anyString(), Mockito.anyLong()), Mockito.never()); |
| 828 | + Assert.assertEquals("router-uuid", ReflectionTestUtils.getField(response, "virtualMachineId")); |
| 829 | + } |
| 830 | + } |
803 | 831 | } |
0 commit comments