|
27 | 27 | import java.util.Arrays; |
28 | 28 | import java.util.Collections; |
29 | 29 | import java.util.List; |
| 30 | +import java.util.stream.Collectors; |
30 | 31 |
|
31 | 32 | import org.junit.Assert; |
32 | 33 | import org.junit.Test; |
@@ -142,12 +143,13 @@ public void testListDistinctHypervisorTypes() { |
142 | 143 | Long zoneId = 1L; |
143 | 144 | List<Hypervisor.HypervisorType> mockResults = List.of(Hypervisor.HypervisorType.KVM, Hypervisor.HypervisorType.XenServer); |
144 | 145 | HostVO host = mock(HostVO.class); |
145 | | - GenericSearchBuilder<HostVO, Hypervisor.HypervisorType> sb = mock(GenericSearchBuilder.class); |
| 146 | + GenericSearchBuilder<HostVO, String> sb = mock(GenericSearchBuilder.class); |
146 | 147 | when(sb.entity()).thenReturn(host); |
147 | | - SearchCriteria<Hypervisor.HypervisorType> sc = mock(SearchCriteria.class); |
| 148 | + SearchCriteria<String> sc = mock(SearchCriteria.class); |
148 | 149 | when(sb.create()).thenReturn(sc); |
149 | | - doReturn(sb).when(hostDao).createSearchBuilder(Hypervisor.HypervisorType.class); |
150 | | - doReturn(mockResults).when(hostDao).customSearch(any(SearchCriteria.class), any()); |
| 150 | + doReturn(sb).when(hostDao).createSearchBuilder(String.class); |
| 151 | + doReturn(mockResults.stream().map(h -> h.name()).collect(Collectors.toList())).when(hostDao) |
| 152 | + .customSearch(any(SearchCriteria.class), any()); |
151 | 153 | List<Hypervisor.HypervisorType> hypervisorTypes = hostDao.listDistinctHypervisorTypes(zoneId); |
152 | 154 | assertEquals(mockResults, hypervisorTypes); |
153 | 155 | Mockito.verify(sc).setParameters("zoneId", zoneId); |
@@ -227,4 +229,22 @@ public void testListDistinctHypervisorArchTypes_WithoutZone() { |
227 | 229 | assertEquals(Hypervisor.HypervisorType.VMware, result.get(0).first()); |
228 | 230 | assertEquals(CPU.CPUArch.amd64, result.get(0).second()); |
229 | 231 | } |
| 232 | + |
| 233 | + @Test |
| 234 | + public void testListDistinctArchTypes() { |
| 235 | + Long clusterId = 1L; |
| 236 | + List<CPU.CPUArch> mockResults = List.of(CPU.CPUArch.amd64, CPU.CPUArch.arm64); |
| 237 | + HostVO host = mock(HostVO.class); |
| 238 | + GenericSearchBuilder<HostVO, String> sb = mock(GenericSearchBuilder.class); |
| 239 | + when(sb.entity()).thenReturn(host); |
| 240 | + SearchCriteria<String> sc = mock(SearchCriteria.class); |
| 241 | + when(sb.create()).thenReturn(sc); |
| 242 | + doReturn(sb).when(hostDao).createSearchBuilder(String.class); |
| 243 | + doReturn(mockResults.stream().map(h -> h.getType()).collect(Collectors.toList())).when(hostDao) |
| 244 | + .customSearch(any(SearchCriteria.class), any()); |
| 245 | + List<CPU.CPUArch> hypervisorTypes = hostDao.listDistinctArchTypes(clusterId); |
| 246 | + assertEquals(mockResults, hypervisorTypes); |
| 247 | + Mockito.verify(sc).setParameters("clusterId", clusterId); |
| 248 | + Mockito.verify(sc).setParameters("type", Host.Type.Routing); |
| 249 | + } |
230 | 250 | } |
0 commit comments