RouterDeploymentDefinition { protected void findVirtualProvider() { final Type type = Type.VirtualRouter; final Long physicalNetworkId = networkModel.getPhysicalNetworkId(guestNetwork); final PhysicalNetworkServiceProvider provider = physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString()); if (provider == null) { throw new CloudRuntimeException(String.format("Cannot find service provider %s in physical network %s", type.toString(), physicalNetworkId)); } vrProvider = vrProviderDao.findByNspIdAndType(provider.getId(), type); if (vrProvider == null) { throw new CloudRuntimeException(String.format("Cannot find virtual router provider %s as service provider %s", type.toString(), provider.getId())); } } 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 testFindVirtualProvider() { when(mockNetworkModel.getPhysicalNetworkId(deployment.guestNetwork)).thenReturn(PHYSICAL_NW_ID); final Type type = Type.VirtualRouter; final PhysicalNetworkServiceProviderVO physicalNwSrvProvider = mock(PhysicalNetworkServiceProviderVO.class); when(physicalProviderDao.findByServiceProvider(PHYSICAL_NW_ID, type.toString())) .thenReturn(physicalNwSrvProvider); when(physicalNwSrvProvider.getId()).thenReturn(PROVIDER_ID); final VirtualRouterProviderVO vrProvider = mock(VirtualRouterProviderVO.class); when(mockVrProviderDao.findByNspIdAndType(PROVIDER_ID, type)) .thenReturn(vrProvider); deployment.findVirtualProvider(); assertEquals("Didn't find and set the VirtualRouterProvider as expected", vrProvider, deployment.getVirtualProvider()); }
@Test(expected = CloudRuntimeException.class) public void testFindVirtualProviderWithNullPhyNwSrvProvider() { when(mockNetworkModel.getPhysicalNetworkId(deployment.guestNetwork)).thenReturn(PHYSICAL_NW_ID); final Type type = Type.VirtualRouter; when(physicalProviderDao.findByServiceProvider(PHYSICAL_NW_ID, type.toString())) .thenReturn(null); deployment.findVirtualProvider(); }
@Test(expected = CloudRuntimeException.class) public void testFindVirtualProviderWithNullVrProvider() { when(mockNetworkModel.getPhysicalNetworkId(deployment.guestNetwork)).thenReturn(PHYSICAL_NW_ID); final Type type = Type.VirtualRouter; final PhysicalNetworkServiceProviderVO physicalNwSrvProvider = mock(PhysicalNetworkServiceProviderVO.class); when(physicalProviderDao.findByServiceProvider(PHYSICAL_NW_ID, type.toString())) .thenReturn(physicalNwSrvProvider); when(physicalNwSrvProvider.getId()).thenReturn(PROVIDER_ID); when(mockVrProviderDao.findByNspIdAndType(PROVIDER_ID, type)) .thenReturn(null); deployment.findVirtualProvider(); }