RouterDeploymentDefinition { protected List<HostPodVO> listByDataCenterIdVMTypeAndStates(final long id, final VirtualMachine.Type type, final VirtualMachine.State... states) { final SearchBuilder<VMInstanceVO> vmInstanceSearch = vmDao.createSearchBuilder(); vmInstanceSearch.and("type", vmInstanceSearch.entity().getType(), SearchCriteria.Op.EQ); vmInstanceSearch.and("states", vmInstanceSearch.entity().getState(), SearchCriteria.Op.IN); final SearchBuilder<HostPodVO> podIdSearch = podDao.createSearchBuilder(); podIdSearch.and("dc", podIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); podIdSearch.select(null, SearchCriteria.Func.DISTINCT, podIdSearch.entity().getId()); podIdSearch.join("vmInstanceSearch", vmInstanceSearch, podIdSearch.entity().getId(), vmInstanceSearch.entity().getPodIdToDeployIn(), JoinBuilder.JoinType.INNER); podIdSearch.done(); final SearchCriteria<HostPodVO> sc = podIdSearch.create(); sc.setParameters("dc", id); sc.setJoinParameters("vmInstanceSearch", "type", type); sc.setJoinParameters("vmInstanceSearch", "states", (Object[]) states); return podDao.search(sc, null); } protected  RouterDeploymentDefinition(final Network guestNetwork, final DeployDestination dest,
                                         final Account owner, final Map<Param, Object> params); Long getServiceOfferingId(); Vpc getVpc(); Network getGuestNetwork(); DeployDestination getDest(); Account getOwner(); Map<Param, Object> getParams(); boolean isRedundant(); DeploymentPlan getPlan(); boolean isVpcRouter(); Pod getPod(); Long getPodId(); List<DomainRouterVO> getRouters(); VirtualRouterProvider getVirtualProvider(); boolean isBasic(); boolean isPublicNetwork(); PublicIp getSourceNatIP(); boolean needsPublicNic(); boolean hasSourceNatService(); List<DomainRouterVO> deployVirtualRouter();  }
@Test public void testListByDataCenterIdVMTypeAndStates() { final VMInstanceVO vmInstanceVO = mock(VMInstanceVO.class); final SearchBuilder<VMInstanceVO> vmInstanceSearch = mock(SearchBuilder.class); when(mockVmDao.createSearchBuilder()).thenReturn(vmInstanceSearch); when(vmInstanceSearch.entity()).thenReturn(vmInstanceVO); when(vmInstanceVO.getType()).thenReturn(VirtualMachine.Type.Instance); when(vmInstanceVO.getState()).thenReturn(VirtualMachine.State.Stopped); when(vmInstanceVO.getPodIdToDeployIn()).thenReturn(POD_ID1); final SearchBuilder<HostPodVO> podIdSearch = mock(SearchBuilder.class); when(mockPodDao.createSearchBuilder()).thenReturn(podIdSearch); final SearchCriteria<HostPodVO> sc = mock(SearchCriteria.class); final HostPodVO hostPodVO = mock(HostPodVO.class); when(podIdSearch.entity()).thenReturn(hostPodVO); when(hostPodVO.getId()).thenReturn(POD_ID1); when(hostPodVO.getDataCenterId()).thenReturn(DATA_CENTER_ID); when(podIdSearch.create()).thenReturn(sc); final List<HostPodVO> expectedPods = mock(List.class); when(mockPodDao.search(sc, null)).thenReturn(expectedPods); final List<HostPodVO> pods = deployment.listByDataCenterIdVMTypeAndStates(DATA_CENTER_ID, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running); assertNotNull(pods); assertEquals(expectedPods, pods); verify(sc, times(1)).setParameters("dc", DATA_CENTER_ID); verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "type", VirtualMachine.Type.User); verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "states", VirtualMachine.State.Starting, VirtualMachine.State.Running); verify(mockPodDao, times(1)).search(sc, null); }