/*
- * Copyright (c) 2015 Inocybe Technologies. All rights reserved.
+ * Copyright (c) 2015, 2016 Inocybe Technologies. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyShort;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
import org.opendaylight.ovsdb.openstack.netvirt.MdsalHelper;
import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-//import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
when(neutronNetwork.getProviderNetworkType()).thenReturn(NetworkHandler.NETWORK_TYPE_VLAN, NetworkHandler.NETWORK_TYPE_GRE);
NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
- Map<NodeId, Node> nodes = new HashMap<NodeId, Node>();
+ Map<NodeId, Node> nodes = new HashMap<>();
nodes.put(mock(NodeId.class), mock(Node.class));
when(nodeCacheManager.getOvsdbNodes()).thenReturn(nodes);
Southbound southbound = mock(Southbound.class);
when(nodeId.getValue()).thenReturn(ID);
Node node = mock(Node.class);
when(node.getNodeId()).thenReturn(nodeId);
- Map<NodeId, Node> nodes = new HashMap<NodeId, Node>();
+ Map<NodeId, Node> nodes = new HashMap<>();
nodes.put(mock(NodeId.class), node);
when(nodeCacheManager.getOvsdbNodes()).thenReturn(nodes);
Southbound southbound = mock(Southbound.class);
when(southbound.getOptionsValue(any(List.class), anyString())).thenReturn(IP);
OvsdbTerminationPointAugmentation intf = mock(OvsdbTerminationPointAugmentation.class);
when(intf.getName()).thenReturn(INTF);
- List<String> intfs = new ArrayList<String>();
+ List<String> intfs = new ArrayList<>();
intfs.add(INTF);
BridgeConfigurationManager bridgeConfigurationManager = mock(BridgeConfigurationManager.class);
when(bridgeConfigurationManager.getAllPhysicalInterfaceNames(any(Node.class))).thenReturn(intfs);
SecurityServicesManager securityServicesManager = mock(SecurityServicesManager.class);
Southbound southbound = mock(Southbound.class);
- PowerMockito.mockStatic(ServiceHelper.class);
- PowerMockito.when(ServiceHelper.getGlobalInstance(ConfigurationService.class, of13Provider)).thenReturn(configurationService);
- PowerMockito.when(ServiceHelper.getGlobalInstance(TenantNetworkManager.class, of13Provider)).thenReturn(tenantNetworkManager);
- PowerMockito.when(ServiceHelper.getGlobalInstance(BridgeConfigurationManager.class, of13Provider)).thenReturn(bridgeConfigurationManager);
- PowerMockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, of13Provider)).thenReturn(nodeCacheManager);
- PowerMockito.when(ServiceHelper.getGlobalInstance(ClassifierProvider.class, of13Provider)).thenReturn(classifierProvider);
- PowerMockito.when(ServiceHelper.getGlobalInstance(IngressAclProvider.class, of13Provider)).thenReturn(ingressAclProvider);
- PowerMockito.when(ServiceHelper.getGlobalInstance(EgressAclProvider.class, of13Provider)).thenReturn(egressAclProvider);
- PowerMockito.when(ServiceHelper.getGlobalInstance(L2ForwardingProvider.class, of13Provider)).thenReturn(l2ForwardingProvider);
- PowerMockito.when(ServiceHelper.getGlobalInstance(SecurityServicesManager.class, of13Provider)).thenReturn(securityServicesManager);
- PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, of13Provider)).thenReturn(southbound);
+ ServiceHelper.overrideGlobalInstance(ConfigurationService.class, configurationService);
+ ServiceHelper.overrideGlobalInstance(TenantNetworkManager.class, tenantNetworkManager);
+ ServiceHelper.overrideGlobalInstance(BridgeConfigurationManager.class, bridgeConfigurationManager);
+ ServiceHelper.overrideGlobalInstance(NodeCacheManager.class, nodeCacheManager);
+ ServiceHelper.overrideGlobalInstance(ClassifierProvider.class, classifierProvider);
+ ServiceHelper.overrideGlobalInstance(IngressAclProvider.class, ingressAclProvider);
+ ServiceHelper.overrideGlobalInstance(EgressAclProvider.class, egressAclProvider);
+ ServiceHelper.overrideGlobalInstance(L2ForwardingProvider.class, l2ForwardingProvider);
+ ServiceHelper.overrideGlobalInstance(SecurityServicesManager.class, securityServicesManager);
+ ServiceHelper.overrideGlobalInstance(Southbound.class, southbound);
of13Provider.setDependencies(mock(BundleContext.class), mock(ServiceReference.class));
BundleContext bundleContext = mock(BundleContext.class);
when(bundleContext.getServiceReference(NetworkingProvider.class.getName())).thenReturn(mock(ServiceReference.class));
- MemberModifier.field(OF13Provider.class, "bundleContext").set(of13Provider , bundleContext);
+ MemberModifier.field(OF13Provider.class, "bundleContext").set(of13Provider, bundleContext);
of13Provider.setDependencies(networkingProviderManager);
- assertEquals("Error, did not return the correct object", getField("networkingProviderManager"), networkingProviderManager);
-}
+ verify(networkingProviderManager).providerAdded(any(ServiceReference.class), same(of13Provider));
+ }
private Object getField(String fieldName) throws Exception {
Field field = OF13Provider.class.getDeclaredField(fieldName);