NiciraNvpElement extends AdapterBase implements ConnectivityProvider, SourceNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
NiciraNvpElementService, ResourceStateAdapter, IpDeployer { protected boolean canHandle(Network network, Service service) { s_logger.debug("Checking if NiciraNvpElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) { return false; } if (!networkModel.isProviderForNetwork(getProvider(), network.getId())) { s_logger.debug("NiciraNvpElement is not a provider for network " + network.getDisplayText()); return false; } if (!ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, Network.Provider.NiciraNvp)) { s_logger.debug("NiciraNvpElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); return false; } return true; }  @Override Map<Service, Map<Capability, String>> getCapabilities(); @Override Provider getProvider(); @Override boolean configure(String name, Map<String, Object> params); @Override boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context); @Override boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context); @Override boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context); @Override boolean shutdown(Network network, ReservationContext context, boolean cleanup); @Override boolean destroy(Network network, ReservationContext context); @Override boolean isReady(PhysicalNetworkServiceProvider provider); @Override boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context); @Override boolean canEnableIndividualServices(); @Override boolean verifyServicesCombination(Set<Service> services); @Override List<Class<?>> getCommands(); @Override @DB NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd); @Override NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(NiciraNvpDeviceVO niciraNvpDeviceVO); @Override boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd); @Override List<NiciraNvpDeviceVO> listNiciraNvpDevices(ListNiciraNvpDevicesCmd cmd); @Override List<? extends Network> listNiciraNvpDeviceNetworks(ListNiciraNvpDeviceNetworksCmd cmd); @Override HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd); @Override HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags); @Override DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage); @Override IpDeployer getIpDeployer(Network network); @Override boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services); @Override boolean applyStaticNats(Network network, List<? extends StaticNat> rules); @Override boolean applyPFRules(Network network, List<PortForwardingRule> rules);  }
@Test public void canHandleTest() { final Network net = mock(Network.class); when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(net.getId()).thenReturn(NETWORK_ID); when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true); assertTrue(element.canHandle(net, Service.Connectivity)); when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan); assertFalse(element.canHandle(net, Service.Connectivity)); when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(false); assertFalse(element.canHandle(net, Service.Connectivity)); when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(false); when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true); assertFalse(element.canHandle(net, Service.Connectivity)); when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true); assertFalse(element.canHandle(net, Service.Dhcp)); }