Merge "Move UuidUtilsTest to the right package (netvirt.api instead of netvirt)."
authorFlavio Fernandes <ffernand@redhat.com>
Wed, 8 Apr 2015 22:53:26 +0000 (22:53 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 8 Apr 2015 22:53:27 +0000 (22:53 +0000)
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/LBaaSPoolMemberHandlerTest.java [new file with mode: 0644]
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtilsTest.java [new file with mode: 0644]
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/EventDispatcherImplTest.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3AdapterTest.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ProviderNetworkManagerImplTest.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImplTest.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/TenantNetworkManagerImplTest.java
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/VlanConfigurationCacheImplTest.java
resources/commons/OVSDB_Southbound.postman_collection

diff --git a/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/LBaaSPoolMemberHandlerTest.java b/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/LBaaSPoolMemberHandlerTest.java
new file mode 100644 (file)
index 0000000..d3b1b3f
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2015 Inocybe and others.  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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+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.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.opendaylight.neutron.spi.INeutronLoadBalancerCRUD;
+import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
+import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
+import org.opendaylight.neutron.spi.INeutronPortCRUD;
+import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
+import org.opendaylight.neutron.spi.NeutronLoadBalancer;
+import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
+import org.opendaylight.neutron.spi.NeutronLoadBalancerPoolMember;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
+import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerConfiguration;
+import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerConfiguration.LoadBalancerPoolMember;
+import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerProvider;
+import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * Unit test for {@link LBaaSPoolMemberHandler}
+ */
+@PrepareForTest(NeutronCacheUtils.class)
+@RunWith(PowerMockRunner.class)
+public class LBaaSPoolMemberHandlerTest {
+
+    @InjectMocks LBaaSPoolMemberHandler lBaaSPoolMemberHandler;
+
+    @Mock private INeutronLoadBalancerPoolCRUD neutronLBPoolCache;
+    @Mock private INeutronLoadBalancerCRUD neutronLBCache;
+    @Mock private LoadBalancerProvider loadBalancerProvider;
+    @Mock private NodeCacheManager nodeCacheManager;
+
+    private NeutronLoadBalancerPoolMember neutronLBMember;
+
+    @Before
+    public void setUp() {
+        neutronLBMember = mock(NeutronLoadBalancerPoolMember.class);
+        when(neutronLBMember.getPoolMemberID()).thenReturn("pool_memberID");
+        when(neutronLBMember.getPoolMemberAddress()).thenReturn("pool_member_address");
+        when(neutronLBMember.getPoolMemberSubnetID()).thenReturn("pool_member_subnetID");
+        when(neutronLBMember.getPoolMemberProtoPort()).thenReturn(1);
+        when(neutronLBMember.getPoolID()).thenReturn("poolID");
+
+        Map.Entry<String,String> providerInfo = mock(Entry.class);
+        when(providerInfo.getKey()).thenReturn("key");
+        when(providerInfo.getValue()).thenReturn("value");
+
+        PowerMockito.mockStatic(NeutronCacheUtils.class);
+        when(NeutronCacheUtils.getMacAddress(any(INeutronPortCRUD.class), anyString(), anyString())).thenReturn("mac_address");
+        when(NeutronCacheUtils.getProviderInformation(any(INeutronNetworkCRUD.class), any(INeutronSubnetCRUD.class), anyString())).thenReturn(providerInfo);
+
+        List<NeutronLoadBalancerPoolMember> members = new ArrayList();
+        NeutronLoadBalancerPoolMember neutronLBPoolMember = mock(NeutronLoadBalancerPoolMember.class);
+        when(neutronLBPoolMember.getPoolMemberAdminStateIsUp()).thenReturn(true);
+        when(neutronLBPoolMember.getPoolMemberSubnetID()).thenReturn("subnetID");
+        when(neutronLBPoolMember.getPoolMemberID()).thenReturn("pool_memberID1");
+        when(neutronLBPoolMember.getPoolMemberProtoPort()).thenReturn(1);
+        members.add(neutronLBPoolMember);
+
+        NeutronLoadBalancerPool neutronLBPool = mock(NeutronLoadBalancerPool.class);
+        when(neutronLBPool.getLoadBalancerPoolProtocol()).thenReturn(LoadBalancerConfiguration.PROTOCOL_TCP);
+        when(neutronLBPool.getLoadBalancerPoolMembers()).thenReturn(members);
+        when(neutronLBPoolCache.getNeutronLoadBalancerPool(anyString())).thenReturn(neutronLBPool);
+
+        List<NeutronLoadBalancer> list_neutronLB = new ArrayList();
+        NeutronLoadBalancer neutronLB = mock(NeutronLoadBalancer.class);
+        when(neutronLB.getLoadBalancerName()).thenReturn("load_balancer_name");
+        when(neutronLB.getLoadBalancerVipAddress()).thenReturn("vip_address");
+        when(neutronLB.getLoadBalancerVipSubnetID()).thenReturn("subnetID");
+        list_neutronLB.add(neutronLB);
+        when(neutronLBCache.getAllNeutronLoadBalancers()).thenReturn(list_neutronLB);
+    }
+
+    /**
+     * Test method {@link LBaaSPoolMemberHandler#canCreateNeutronLoadBalancerPoolMember(NeutronLoadBalancerPoolMember)}
+     */
+    @Test
+    public void testCanCreateNeutronLoadBalancerPoolMember() {
+        when(neutronLBMember.getPoolID())
+                                    .thenReturn(null)  // to test HTTP_BAD_REQUEST
+                                    .thenReturn("poolID"); // to test HTTP_OK
+
+        Map.Entry<String,String> providerInfo = mock(Entry.class);
+        when(providerInfo.getKey()).thenReturn("key");
+        when(providerInfo.getValue()).thenReturn("value");
+        when(NeutronCacheUtils.getProviderInformation(any(INeutronNetworkCRUD.class), any(INeutronSubnetCRUD.class), anyString()))
+                                    .thenReturn(providerInfo)
+                                    .thenReturn(null); // to test HTTP_NOT_ACCEPTABLE
+
+
+        assertEquals("Error, canCreateNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_BAD_REQUEST, lBaaSPoolMemberHandler.canCreateNeutronLoadBalancerPoolMember(neutronLBMember));
+        assertEquals("Error, canCreateNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_OK, lBaaSPoolMemberHandler.canCreateNeutronLoadBalancerPoolMember(neutronLBMember));
+        assertEquals("Error, canCreateNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_NOT_ACCEPTABLE, lBaaSPoolMemberHandler.canCreateNeutronLoadBalancerPoolMember(neutronLBMember));
+    }
+
+    /**
+     * Test method {@link LBaaSPoolMemberHandler#canUpdateNeutronLoadBalancerPoolMember(NeutronLoadBalancerPoolMember, NeutronLoadBalancerPoolMember)}
+     */
+    @Test
+    public void testCanUpdateNeutronLoadBalancerPoolMember() {
+        assertEquals("Error, did not return the correct HTTP flag", HttpURLConnection.HTTP_NOT_IMPLEMENTED, lBaaSPoolMemberHandler.canUpdateNeutronLoadBalancerPoolMember(any(NeutronLoadBalancerPoolMember.class), any(NeutronLoadBalancerPoolMember.class)));
+    }
+
+    /**
+     * Test method {@link LBaaSPoolMemberHandler#canDeleteNeutronLoadBalancerPoolMember(NeutronLoadBalancerPoolMember)}
+     */
+    @Test
+    public void testCanDeleteNeutronLoadBalancerPoolMember() {
+        when(neutronLBMember.getPoolID())
+                                    .thenReturn(null)  // to test HTTP_BAD_REQUEST
+                                    .thenReturn("poolID"); // to test HTTP_OK
+
+        Map.Entry<String,String> providerInfo = mock(Entry.class);
+        when(providerInfo.getKey()).thenReturn("key");
+        when(providerInfo.getValue()).thenReturn("value");
+        when(NeutronCacheUtils.getProviderInformation(any(INeutronNetworkCRUD.class), any(INeutronSubnetCRUD.class), anyString()))
+                                    .thenReturn(providerInfo)
+                                    .thenReturn(null); // to test HTTP_NOT_ACCEPTABLE
+
+
+        assertEquals("Error, canDeleteNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_BAD_REQUEST, lBaaSPoolMemberHandler.canDeleteNeutronLoadBalancerPoolMember(neutronLBMember));
+        assertEquals("Error, canDeleteNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_OK, lBaaSPoolMemberHandler.canDeleteNeutronLoadBalancerPoolMember(neutronLBMember));
+        assertEquals("Error, canDeleteNeutronLoadBalancerPoolMember() didn't return the correct HTTP flag", HttpURLConnection.HTTP_NOT_ACCEPTABLE, lBaaSPoolMemberHandler.canDeleteNeutronLoadBalancerPoolMember(neutronLBMember));
+    }
+
+    /**
+     * Test method {@link LBaaSPoolMemberHandler#processEvent(AbstractEvent)}
+     */
+    @Test
+    public void testProcessEvent(){
+        LBaaSPoolMemberHandler lbaasPoolMemberHandlerSpy = Mockito.spy(lBaaSPoolMemberHandler);
+
+        NorthboundEvent ev = mock(NorthboundEvent.class);
+        when(ev.getLoadBalancerPoolMember()).thenReturn(neutronLBMember);
+
+        List<Node> list_node = new ArrayList();
+        list_node .add(mock(Node.class));
+        when(nodeCacheManager.getNodes()).thenReturn(list_node);
+
+        when(ev.getAction()).thenReturn(Action.ADD);
+        lbaasPoolMemberHandlerSpy.processEvent(ev);
+        verify(lbaasPoolMemberHandlerSpy, times(1)).extractLBConfiguration(any(NeutronLoadBalancerPoolMember.class));
+
+        when(ev.getAction()).thenReturn(Action.DELETE);
+        lbaasPoolMemberHandlerSpy.processEvent(ev);
+        verify(lbaasPoolMemberHandlerSpy, times(2)).extractLBConfiguration(any(NeutronLoadBalancerPoolMember.class)); // 1 + 1 above
+
+        when(ev.getAction()).thenReturn(Action.UPDATE);
+        lbaasPoolMemberHandlerSpy.processEvent(ev);
+        verify(lbaasPoolMemberHandlerSpy, times(2)).extractLBConfiguration(any(NeutronLoadBalancerPoolMember.class)); // same as before as nothing as been done
+    }
+
+    /**
+     * Test method {@link LBaaSPoolMemberHandler#extractLBConfiguration(NeutronLoadBalancerPoolMember)}
+     */
+    @Test
+    public void testExtractLBConfiguration() {
+        LoadBalancerConfiguration lbConfig = lBaaSPoolMemberHandler.extractLBConfiguration(neutronLBMember);
+
+        verify(neutronLBPoolCache, times(1)).getNeutronLoadBalancerPool(anyString());
+        verify(neutronLBCache, times(1)).getAllNeutronLoadBalancers();
+
+        // make sure the load balancer configuration was correctly populated
+        assertEquals("Error, did not return the correct value",  "key", lbConfig.getProviderNetworkType());
+        assertEquals("Error, did not return the correct value",  "value", lbConfig.getProviderSegmentationId());
+        assertEquals("Error, did not return the correct value",  "mac_address", lbConfig.getVmac());
+
+        // make sure the load balancer pool member was correctly populated
+        LoadBalancerPoolMember member = lbConfig.getMembers().get("pool_memberID");
+        assertEquals("Error, did not return the correct value",  "pool_member_address", member.getIP());
+        assertEquals("Error, did not return the correct value",  "mac_address", member.getMAC());
+        assertEquals("Error, did not return the correct value",  LoadBalancerConfiguration.PROTOCOL_TCP, member.getProtocol());
+        assertTrue("Error, did not return the correct value",  1 ==  member.getPort());
+    }
+}
diff --git a/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtilsTest.java b/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtilsTest.java
new file mode 100644 (file)
index 0000000..170978c
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015 Inocybe and others.  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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
+import org.opendaylight.neutron.spi.INeutronPortCRUD;
+import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
+import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.neutron.spi.NeutronPort;
+import org.opendaylight.neutron.spi.NeutronSubnet;
+import org.opendaylight.neutron.spi.Neutron_IPs;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * Unit test for {@link NeutronCacheUtils}
+ */
+@RunWith(PowerMockRunner.class)
+public class NeutronCacheUtilsTest {
+
+    /**
+     * Test method {@link NeutronCacheUtils#getMacAddress(INeutronPortCRUD, String, String)}
+     */
+    @Test
+    public void testGetMacAddress(){
+        INeutronPortCRUD neutronPortsCache = mock(INeutronPortCRUD.class);
+        NeutronPort port = mock(NeutronPort.class);
+        Neutron_IPs ip = mock(Neutron_IPs.class);
+        when(ip.getIpAddress()).thenReturn("ip_address");
+        when(ip.getSubnetUUID()).thenReturn("subnetUUID");
+        List<Neutron_IPs> list_fixedIP = new ArrayList();
+        list_fixedIP.add(ip);
+        when(port.getFixedIPs()).thenReturn(list_fixedIP);
+        when(port.getMacAddress()).thenReturn("mac_address");
+        List<NeutronPort> list_port = new ArrayList();
+        list_port.add(port);
+
+        when(neutronPortsCache.getAllPorts()).thenReturn(list_port);
+
+        assertEquals("Error, getMacAddress() did not return the correct value", "mac_address", NeutronCacheUtils.getMacAddress(neutronPortsCache, "subnetUUID", "ip_address"));
+    }
+
+    /**
+     * Test method {@link NeutronCacheUtils#getProviderInformation(INeutronNetworkCRUD, INeutronSubnetCRUD, String)}
+     */
+    @Test
+    public void testGetProviderInformation() {
+        INeutronSubnetCRUD neutronSubnetCache = mock(INeutronSubnetCRUD.class);
+        NeutronSubnet subnet = mock(NeutronSubnet.class);
+        when(subnet.getID()).thenReturn("subnetUUID");
+        when(subnet.getNetworkUUID()).thenReturn("networkUUID");
+        List<NeutronSubnet> list_subnet = new ArrayList();
+        list_subnet.add(subnet);
+
+        when(neutronSubnetCache.getAllSubnets()).thenReturn(list_subnet );
+
+        INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
+        NeutronNetwork network = mock(NeutronNetwork.class);
+        when(network.getID()).thenReturn("networkUUID");
+        when(network.getProviderNetworkType()).thenReturn("network_type_1");
+        when(network.getProviderSegmentationID()).thenReturn("network_segID");
+        List<NeutronNetwork> list_network = new ArrayList();
+        list_network.add(network);
+
+        when(neutronNetworkCache.getAllNetworks()).thenReturn(list_network);
+
+        Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(
+                network.getProviderNetworkType(), network.getProviderSegmentationID());
+
+        assertEquals("Error, getProviderInformation() did not return the correct values", entry, NeutronCacheUtils.getProviderInformation(neutronNetworkCache, neutronSubnetCache, "subnetUUID"));
+    }
+}
index 66ba75f8d9ca1b9e82668055b6037ab433487486..0796d73f546b4dc89bb38584c0341ab2358455df 100644 (file)
@@ -30,7 +30,7 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.osgi.framework.ServiceReference;
 
 /**
- * Unit test for class EventDispatcherImpl
+ * Unit test for {@link EventDispatcherImpl}
  */
 @RunWith(MockitoJUnitRunner.class)
 public class EventDispatcherImplTest {
@@ -39,7 +39,7 @@ public class EventDispatcherImplTest {
     @InjectMocks EventDispatcherImpl eventDispatcherImpl;
 
     private AbstractEvent.HandlerType handlerTypeObject = AbstractEvent.HandlerType.NEUTRON_FLOATING_IP;
-    public ServiceReference ref = mock(ServiceReference.class);
+    private ServiceReference ref = mock(ServiceReference.class);
 
     @Before
     public void setUp() {
@@ -53,10 +53,11 @@ public class EventDispatcherImplTest {
     }
 
     /**
-     * Test method {@link EventDispatcherImpl#eventHandlerAdded(ServiceReference, AbstractHandler)}
+     * Test methods {@link EventDispatcherImpl#eventHandlerRemoved(ServiceReference)}
+     * and {@link EventDispatcherImpl#eventHandlerAdded(ServiceReference, AbstractHandler)}
      */
     @Test
-    public void testeventHandlerAdded() throws Exception{
+    public void testHandlerAddedAndRemoved() throws Exception{
         AbstractHandler[] handlers = ( AbstractHandler[]) getClassField("handlers");
 
         assertNotEquals("Error, handler should be null", handlers[handlerTypeObject.ordinal()], handler);
@@ -64,18 +65,6 @@ public class EventDispatcherImplTest {
         eventDispatcherImpl.eventHandlerAdded(ref, handler);
 
         assertEquals("Error, did not return the added handler", handlers[handlerTypeObject.ordinal()], handler);
-    }
-
-    /**
-     * Test method {@link EventDispatcherImpl#eventHandlerRemoved(ServiceReference)}
-     */
-    @Test
-    public void testHandlerRemoved() throws Exception{
-        AbstractHandler[] handlers = ( AbstractHandler[]) getClassField("handlers");
-
-        eventDispatcherImpl.eventHandlerAdded(ref, handler);
-
-        assertEquals("Error, did not return the added handler", handlers[handlerTypeObject.ordinal()], handler);
 
         eventDispatcherImpl.eventHandlerRemoved(ref);
 
index cbda2c123e580355f38ec8a8ef5275ffd050c892..d269e8424f054400102a002227d2fc4c1354d252 100644 (file)
@@ -42,14 +42,7 @@ import org.opendaylight.ovsdb.lib.notation.Column;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
-import org.opendaylight.ovsdb.openstack.netvirt.api.ArpProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
-import org.opendaylight.ovsdb.openstack.netvirt.api.InboundNatProvider;
-import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
-import org.opendaylight.ovsdb.openstack.netvirt.api.MultiTenantAwareRouter;
-import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
-import org.opendaylight.ovsdb.openstack.netvirt.api.OutboundNatProvider;
-import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
@@ -69,6 +62,8 @@ import org.powermock.modules.junit4.PowerMockRunner;
 @RunWith(PowerMockRunner.class)
 public class NeutronL3AdapterTest {
 
+    @InjectMocks NeutronL3Adapter neutronL3Adapter;
+
     @Mock private ConfigurationService configurationService;
     @Mock private TenantNetworkManager tenantNetworkManager;
     @Mock private OvsdbConfigurationService ovsdbConfigurationService;
@@ -76,19 +71,7 @@ public class NeutronL3AdapterTest {
     @Mock private INeutronNetworkCRUD neutronNetworkCache;
     @Mock private INeutronSubnetCRUD neutronSubnetCache;
     @Mock private INeutronPortCRUD neutronPortCache;
-
-    @Mock private NeutronPort neutronPort;
-    @Mock private Neutron_IPs neutronIP;
-    @Mock private NeutronRouter neutronRouter;
-    @Mock private NeutronRouter_Interface neutronRouterInterface;
-    @Mock private NeutronSubnet neutronSubnet;
-    @Mock private NeutronNetwork neutronNetwork;
-    @Mock private Node node;
-    @Mock private NodeId nodeID;
-    @Mock private Row row;
-    @Mock private Bridge bridge;
-    @Mock private Status status;
-    @InjectMocks NeutronL3Adapter neutronL3Adapter;
+    @Mock NeutronPort neutronPort;
 
     private Set<String> inboundIpRewriteCache;
     private Set<String> outboundIpRewriteCache;
@@ -134,6 +117,17 @@ public class NeutronL3AdapterTest {
     }
 
     private void setUpVar(){
+        Neutron_IPs neutronIP = mock(Neutron_IPs.class);
+        NeutronRouter neutronRouter = mock(NeutronRouter.class);
+
+        NeutronSubnet neutronSubnet = mock(NeutronSubnet.class);
+        NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
+        Node node = mock(Node.class);
+        NodeId nodeID = mock(NodeId.class);
+        Row row = mock(Row.class);
+        Bridge bridge = mock(Bridge.class);
+        Status status = mock(Status.class);
+
         List<Neutron_IPs> list_neutronIP = new ArrayList<Neutron_IPs>();
         list_neutronIP.add(neutronIP);
 
@@ -159,9 +153,6 @@ public class NeutronL3AdapterTest {
         when(neutronIP.getSubnetUUID()).thenReturn("subnetUUID");
         when(neutronIP.getIpAddress()).thenReturn(HOST_ADDRESS);
 
-        when(neutronRouterInterface.getPortUUID()).thenReturn("portUUID");
-        when(neutronRouterInterface.getSubnetUUID()).thenReturn("subnetUUID");
-
         when(neutronPortCache.getAllPorts()).thenReturn(list_neutronPort);
         when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
 
@@ -252,6 +243,9 @@ public class NeutronL3AdapterTest {
 
         // populate subnetIdToRouterInterfaceCache to pass the
         // if (neutronRouterInterface != null)
+        NeutronRouter_Interface neutronRouterInterface = mock(NeutronRouter_Interface.class);
+        when(neutronRouterInterface.getPortUUID()).thenReturn("portUUID");
+        when(neutronRouterInterface.getSubnetUUID()).thenReturn("subnetUUID");
         subnetIdToRouterInterfaceCache.put("subnetUUID", neutronRouterInterface);
 
         /* device owner = "" */
@@ -325,7 +319,6 @@ public class NeutronL3AdapterTest {
         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
         assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
-
     }
 
 }
index fb93983447d87b761b4789ab77c49170a0c63056..4a4c85e215caf4b996c497db97ef58e7faa83377 100644 (file)
@@ -11,24 +11,20 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.lang.reflect.Field;
 import java.util.HashMap;
-import java.util.Random;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
 import org.mockito.Spy;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.osgi.framework.ServiceReference;
 
 /**
- * Unit test for class ProviderNetworkManagerImpl
- *
- * TODO In order to have deeper tests, private inner class
- *  ProviderEntry of ProviderNetworkManager should be public.
+ * Unit test for {@link ProviderNetworkManagerImpl}
  */
 @RunWith(MockitoJUnitRunner.class)
 public class ProviderNetworkManagerImplTest {
@@ -36,51 +32,40 @@ public class ProviderNetworkManagerImplTest {
     @InjectMocks private ProviderNetworkManagerImpl providerNetworkManagerImpl;
     @Spy private HashMap<Node, NetworkingProvider> nodeToProviderMapping;
 
-    private Random r = new Random();
-
     /**
      * Test method {@link ProviderNetworkManagerImpl#getProvider(Node)}
      */
     @Test
     public void testGetProvider(){
+        // TODO test the method with no networkingProvider in the map
+        // Could not be done as ProviderEntry is a private inner class of ProviderNetworkManagerImpl
+//        assertNotNull("Error, did not return the networkingProvider of the specified node", providerNetworkManagerImpl.getProvider(any(Node.class));
+
         Node node = mock(Node.class);
         NetworkingProvider networkingProvider = mock(NetworkingProvider.class);
-
-        // populate nodeToProviderMapping
         nodeToProviderMapping.put(node, networkingProvider);
-
-        // test when nodeToProviderMapping is populate
         assertEquals("Error, did not return the networkingProvider of the specified node", networkingProvider, providerNetworkManagerImpl.getProvider(node));
     }
 
     /**
-     * Test method {@link ProviderNetworkManagerImpl#providerAdded(ServiceReference, NetworkingProvider)}
+     * Test methods {@link ProviderNetworkManagerImpl#providerRemoved(ServiceReference)}
+     * and {@link ProviderNetworkManagerImpl#providerAdded(ServiceReference, NetworkingProvider)}
      */
     @Test
-    public void testProviderAdded(){
-        ServiceReference ref = mock(ServiceReference.class);
+    public void testProviderAddedAndRemoved() throws Exception {
+        Field field = ProviderNetworkManagerImpl.class.getDeclaredField("providers");
+        field.setAccessible(true);
+        HashMap map = (HashMap) field.get(providerNetworkManagerImpl);
 
-        // configure ref
-        when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)).thenReturn(r.nextLong());
-        when(ref.getProperty(Constants.SOUTHBOUND_PROTOCOL_PROPERTY)).thenReturn("proto");
-        when(ref.getProperty(Constants.OPENFLOW_VERSION_PROPERTY)).thenReturn("of");
-        when(ref.getProperty(Constants.PROVIDER_TYPE_PROPERTY)).thenReturn("provider");
+        ServiceReference ref = mock(ServiceReference.class);
+        when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)).thenReturn(Long.valueOf(1));
 
-        // nothing much to test
         providerNetworkManagerImpl.providerAdded(ref, mock(NetworkingProvider.class));
-    }
 
-    /**
-     * Test method {@link ProviderNetworkManagerImpl#providerRemoved(ServiceReference)}
-     */
-    @Test
-    public void testProviderRemoved(){
-        ServiceReference ref = mock(ServiceReference.class);
-
-        // configure ref
-        when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)).thenReturn(r.nextLong());
+        assertEquals("Error, providerAdded() did not add the provider", 1, map.size());
 
-        // nothing much to test
         providerNetworkManagerImpl.providerRemoved(ref);
+
+        assertEquals("Error, providerRemoved() did not remove the provider", 0, map.size());
     }
 }
index db40bfb2daf9ec66251bb6c64db46163d2d4c5cb..6b3145a2b9e2725e366b8f8f77c06b14e22c2209 100644 (file)
@@ -33,34 +33,34 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
 
 /**
- * Unit test for class SecurityServicesImpl
+ * Unit test for {@link SecurityServicesImpl}
  */
 @RunWith(MockitoJUnitRunner.class)
 public class SecurityServicesImplTest {
 
-    @Mock private Interface intf;
-    @Mock private NeutronPort neutronPort;
-
     @InjectMocks private SecurityServicesImpl securityServicesImpl;
-    @InjectMocks private INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
+    @InjectMocks private INeutronPortCRUD neutronPortService = mock(INeutronPortCRUD.class);
+
+    @Mock Interface intf;
 
     private List<NeutronSecurityGroup> securityGroups = new ArrayList<NeutronSecurityGroup>();
 
     @Before
     public void setUp(){
+        NeutronPort neutronPort = mock(NeutronPort.class);
+
         Map<String, String> externalIds =new HashMap<String, String>();
         externalIds.put(Constants.EXTERNAL_ID_INTERFACE_ID, "mapValue");
         Column<GenericTableSchema, Map<String, String>> columnMock = mock(Column.class);
 
         securityGroups.add(mock(NeutronSecurityGroup.class));
 
-        // configure interface
         when(intf.getExternalIdsColumn()).thenReturn(columnMock);
         when(columnMock.getData()).thenReturn(externalIds);
 
-        // configure neutronPort
         when(neutronPort.getSecurityGroups()).thenReturn(securityGroups);
-        when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
+        when(neutronPort.getDeviceOwner()).thenReturn("deviceOwner");
+        when(neutronPortService.getPort(anyString())).thenReturn(neutronPort);
     }
 
     /**
@@ -68,10 +68,6 @@ public class SecurityServicesImplTest {
      */
     @Test
     public void testIsPortSecurityReady(){
-        // configure neutronPort
-        when(neutronPort.getDeviceOwner()).thenReturn("deviceOwner");
-
-        //test
         assertTrue("Error, did not return expected boolean for isPortSecurityReady", securityServicesImpl.isPortSecurityReady(intf));
     }
 
@@ -80,7 +76,6 @@ public class SecurityServicesImplTest {
      */
     @Test
     public void testSecurityGroupInPort(){
-        // test
         assertEquals("Error, did not return the good neutronSecurityGroup of securityGroups", securityGroups.toArray()[0], securityServicesImpl.getSecurityGroupInPort(intf));
     }
 }
index 12d6cb1d09b1dc5a465067c0b24e2579616df3dd..0b0ffb02e32ffd8a4003f6ebf048cbac4570dd3f 100644 (file)
@@ -16,10 +16,13 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 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.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -40,6 +43,7 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager;
 import org.opendaylight.ovsdb.openstack.netvirt.api.VlanConfigurationCache;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
+import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
 import org.opendaylight.ovsdb.plugin.api.Status;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.schema.openvswitch.Interface;
@@ -47,7 +51,7 @@ import org.opendaylight.ovsdb.schema.openvswitch.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 
 /**
- * Unit test for class TenantNetworkManagerImpl
+ * Unit test for {@link TenantNetworkManagerImpl}
  */
 @RunWith(MockitoJUnitRunner.class)
 public class TenantNetworkManagerImplTest {
@@ -56,6 +60,7 @@ public class TenantNetworkManagerImplTest {
     @Mock private INeutronPortCRUD neutronCache;
     @Mock private OvsdbConfigurationService ovsdbConfigurationService;
     @Mock private NetworkingProviderManager networkingProviderManager;
+    @Mock private OvsdbConnectionService ovsdbConnectionService;
 
     @InjectMocks private TenantNetworkManagerImpl tenantNetworkManagerImpl;
     @InjectMocks private INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
@@ -68,13 +73,12 @@ public class TenantNetworkManagerImplTest {
      */
     @Test
     public void testGetInternalVlan() {
-        // configure vlanConfigurationCache
         when(vlanConfigurationCache.getInternalVlan(any(Node.class), eq(NETWORK_ID))).thenReturn(10);
 
-        // test on an existing internal vlan
         assertEquals("Error, did not return the correct internalVlan" , 10, tenantNetworkManagerImpl.getInternalVlan(mock(Node.class), NETWORK_ID));
-        // test on a missing internal vlan
         assertEquals("Error, did not return the correct internalVlan", 0, tenantNetworkManagerImpl.getInternalVlan(mock(Node.class), "unexistingNetwork"));
+
+        verify(vlanConfigurationCache, times(2)).getInternalVlan(any(Node.class), anyString());
     }
 
     /**
@@ -82,13 +86,12 @@ public class TenantNetworkManagerImplTest {
      */
     @Test
     public void testReclaimInternalVlan() {
-        // configure vlanConfigurationCache
         when(vlanConfigurationCache.reclaimInternalVlan(any(Node.class), eq(NETWORK_ID))).thenReturn(10);
 
-        // test on an existing internal vlan
         tenantNetworkManagerImpl.reclaimInternalVlan(mock(Node.class), NETWORK_ID, mock(NeutronNetwork.class));
-        // test on a missing internal vlan
         tenantNetworkManagerImpl.reclaimInternalVlan(mock(Node.class), "unexistingNetwork", mock(NeutronNetwork.class));
+
+        verify(vlanConfigurationCache, times(2)).reclaimInternalVlan(any(Node.class), anyString());
     }
 
     /**
@@ -101,18 +104,16 @@ public class TenantNetworkManagerImplTest {
         GenericTableSchema tableSchema = mock(GenericTableSchema.class);
         Status status = mock(Status.class);
 
-        // configure port
         when(port.getRow()).thenReturn(row);
         when(port.getSchema()).thenReturn(tableSchema);
 
-        // configure vlanConfigurationCache
         when(vlanConfigurationCache.getInternalVlan(any(Node.class), anyString())).thenReturn(10);
-        // configure ovsdbConfigurationService
         when(ovsdbConfigurationService.createTypedRow(any(Node.class), same(Port.class))).thenReturn(port);
         when(ovsdbConfigurationService.updateRow(any(Node.class), anyString(), anyString(), anyString(), any(Row.class))).thenReturn(status);
 
-        // test
         tenantNetworkManagerImpl.programInternalVlan(mock(Node.class), NETWORK_ID, mock(NeutronNetwork.class));
+
+        verify(vlanConfigurationCache, times(1)).getInternalVlan(any(Node.class), anyString());
     }
 
     /**
@@ -139,36 +140,32 @@ public class TenantNetworkManagerImplTest {
         ArrayList<NeutronNetwork> listNeutronNetwork = new ArrayList<NeutronNetwork>();
         listNeutronNetwork.add(neutronNetwork);
 
-        // configure neutronNetwork
         when(neutronNetwork.getProviderSegmentationID()).thenReturn("segId");
         when(neutronNetwork.getNetworkUUID()).thenReturn("networkUUID");
         when(neutronNetworkCache.getAllNetworks()).thenReturn(listNeutronNetwork);
 
-        // test method getNetworkId
         assertEquals("Error, did not return the UUID of the correct network", listNeutronNetwork.get(0).getNetworkUUID(), tenantNetworkManagerImpl.getNetworkId("segId"));
 
-        // configure networkingProvider
         when(networkingProviderManager.getProvider(any(Node.class))).thenReturn(networkingProvider);
         when(networkingProvider.hasPerTenantTunneling()).thenReturn(true);
 
-        // configure vlanConfigurationCache
         when(vlanConfigurationCache.getInternalVlan(any(Node.class), anyString())).thenReturn(10);
 
-        // configure ovsdbConfigurationService
         when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(map);
         when(ovsdbConfigurationService.getTypedRow(any(Node.class), same(Interface.class),
                 any(Row.class))).thenReturn(intf);
 
-        // configure interface
         when(intf.getExternalIdsColumn()).thenReturn(columnMock);
         when(columnMock.getData()).thenReturn(externalIds);
 
-        // configure neutronPort
         when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
         when(neutronPort.getNetworkUUID()).thenReturn("networkUUID");
 
-        // test method isTenantNetworkPresentInNode
         assertTrue("Error, did not return correct boolean for isTenantNetworkPresentInNode", tenantNetworkManagerImpl.isTenantNetworkPresentInNode(mock(Node.class), "segId"));
+
+
+        verify(networkingProviderManager, times(1)).getProvider(any(Node.class));
+        verify(vlanConfigurationCache, times(1)).getInternalVlan(any(Node.class), anyString());
     }
 
     /**
@@ -180,12 +177,13 @@ public class TenantNetworkManagerImplTest {
         ArrayList<NeutronNetwork> listNeutronNetwork = new ArrayList<NeutronNetwork>();
         listNeutronNetwork.add(neutronNetwork);
 
-        // configure neutronNetwork
         when(neutronNetwork.getProviderSegmentationID()).thenReturn("segId");
         when(neutronNetwork.getNetworkUUID()).thenReturn("networkUUID");
         when(neutronNetworkCache.getAllNetworks()).thenReturn(listNeutronNetwork);
 
         assertEquals("Error, did not return the UUID of the correct network", listNeutronNetwork.get(0).getNetworkUUID(), tenantNetworkManagerImpl.getNetworkId("segId"));
+
+        verify(neutronNetworkCache, times(1)).getAllNetworks();
     }
 
     /**
@@ -200,17 +198,17 @@ public class TenantNetworkManagerImplTest {
         NeutronPort neutronPort = mock(NeutronPort.class);
         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
 
-        // configure interface
         when(intf.getExternalIdsColumn()).thenReturn(columnMock);
         when(columnMock.getData()).thenReturn(externalIds);
 
-        // configure neutronPort
         when(neutronPort.getNetworkUUID()).thenReturn("neutronUUID");
         when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
-        // configure neutronNetwork
         when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
 
         assertEquals("Error, did not return the correct tenant", neutronNetwork, tenantNetworkManagerImpl.getTenantNetwork(intf));
+
+        verify(neutronPortCache, times(1)).getPort(anyString());
+        verify(neutronNetworkCache, times(1)).getNetwork(anyString());
     }
 
     /**
@@ -218,9 +216,20 @@ public class TenantNetworkManagerImplTest {
      */
     @Test
     public void testNetworkCreated() {
-        // configure vlanConfigurationCache
+        int numberOfNode = 10;
         when(vlanConfigurationCache.assignInternalVlan(any(Node.class), anyString())).thenReturn(10);
 
+        List<Node> nodes = new ArrayList();
+        for (int i = 0; i<numberOfNode; i++) {
+            nodes.add(mock(Node.class));
+        }
+        when(ovsdbConnectionService.getNodes()).thenReturn(nodes);
+
+        tenantNetworkManagerImpl.networkCreated(NETWORK_ID);
+
+        verify(ovsdbConnectionService, times(1)).getNodes();
+        verify(vlanConfigurationCache, times(numberOfNode)).assignInternalVlan(any(Node.class), anyString());
+
         assertEquals("Error, did not return the correct network id", 10,tenantNetworkManagerImpl.networkCreated(mock(Node.class), NETWORK_ID));
     }
 }
index 6925064c298d2be4fbb230cc683b2204b5e13cec..58d4d1f4ad5130e2b88f59dabb65276afb9b9f6b 100644 (file)
@@ -15,7 +15,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.HashSet;
-import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -36,7 +35,7 @@ import org.opendaylight.ovsdb.schema.openvswitch.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 
 /**
- * Unit test for class VlanConfigurationCacheImpl
+ * Unit test for {@link VlanConfigurationCacheImpl}
  */
 @RunWith(MockitoJUnitRunner.class)
 public class VlanConfigurationCacheImplTest {
@@ -61,10 +60,8 @@ public class VlanConfigurationCacheImplTest {
         ovsTable = new ConcurrentHashMap<>();
         ovsTable.put(NODE_UUID, row);
 
-        ConcurrentHashMap<String, Row> portRows = ovsTable;
-
         Set<Long> tags = new HashSet<Long>();
-        tags.add(new Random().nextLong());
+        tags.add(Long.valueOf(1));
 
         UUID uuid = mock(UUID.class);
         Set<UUID> uuidSet = new HashSet<>();
@@ -76,24 +73,19 @@ public class VlanConfigurationCacheImplTest {
         Interface iface = mock(Interface.class);
         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
 
-        // configure ovsdbConfigurationService
         when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(ovsTable);
-        when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(portRows);
         when(ovsdbConfigurationService.getTypedRow(any(Node.class), same(Port.class), any(Row.class))).thenReturn(port);
 
-        // configure port
         when(port.getTagColumn()).thenReturn(longColumnMock);
         when(longColumnMock.getData()).thenReturn(tags);
         when(port.getInterfacesColumn()).thenReturn(uuidColumnMock);
         when(uuidColumnMock.getData()).thenReturn(uuidSet);
 
-        // configure ovsdbConfigurationService
         when(ovsdbConfigurationService.getRow(any(Node.class), anyString(), anyString())).thenReturn(row);
         when(ovsdbConfigurationService.getTypedRow(any(Node.class), same(Interface.class), any(Row.class))).thenReturn(iface);
 
-        // configure neutronNetwork
         when(tenantNetworkManagerImpl.getTenantNetwork(any(Interface.class))).thenReturn(neutronNetwork);
-        when(neutronNetwork.getNetworkUUID()).thenReturn("networkUUID");
+        when(neutronNetwork.getNetworkUUID()).thenReturn(NETWORK_ID);
     }
 
     /**
@@ -101,17 +93,23 @@ public class VlanConfigurationCacheImplTest {
      */
     @Test
     public void testAssignInternalVlan() {
-        // test
-        assertEquals("Error, did not return the correct internalVlanId (first added)", 1, (int) vlanConfigurationCacheImpl.assignInternalVlan(mock(Node.class), NETWORK_ID));
-        assertEquals("Error, did not return the correct internalVlanId (second added)",2, (int) vlanConfigurationCacheImpl.assignInternalVlan(mock(Node.class), NETWORK_ID + "1"));
-        }
+        assertEquals("Error, did not return the correct internalVlanId (first added)", 1, (int) vlanConfigurationCacheImpl.assignInternalVlan(any(Node.class), NETWORK_ID));
+        assertEquals("Error, did not return the correct internalVlanId (second added)", 2, (int) vlanConfigurationCacheImpl.assignInternalVlan(any(Node.class), NETWORK_ID + "1"));
+    }
 
     /**
-     * Test method {@linkp VlanConfigurationCacheImpl#reclaimInternalVlan(Node, String)}
+     * Test method {@link VlanConfigurationCacheImpl#reclaimInternalVlan(Node, String)}
      */
     @Test
     public void testReclaimInternalVlan(){
-        // test
-        assertEquals("Error, did not return the correct internalVlanId",0, (int) vlanConfigurationCacheImpl.reclaimInternalVlan(any(Node.class), NETWORK_ID));
+        assertEquals("Error, did not return the correct internalVlanId", 1, (int) vlanConfigurationCacheImpl.reclaimInternalVlan(any(Node.class), NETWORK_ID));
+    }
+
+    /**
+     * Test method {@link VlanConfigurationCacheImpl#getInternalVlan(Node, String)}
+     */
+    @Test
+    public void testGetInternalVlan(){
+        assertEquals("Error, did not return the correct internalVlan", 1, (int) vlanConfigurationCacheImpl.getInternalVlan(any(Node.class), NETWORK_ID));
     }
 }
index 09a72d9187a1f4f52ee940010e0c230769b0cd13..5acbc093bea2dd348549f1750e0c106c96888461 100644 (file)
-{
-   "id":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-   "name":"Ovsdb Southbound Collection",
-   "timestamp":1424977469540,
-   "order":[
-      "96457d05-3f7d-981b-cf11-c9260b4b9391",
-      "c7d7ac50-215a-2014-49c5-99791c494797",
-      "dba73a23-c978-718e-d671-29cbb23935fd",
-      "84c5f57e-14aa-a096-0a23-193828da309c",
-      "beb434cf-7f69-83a5-d1f3-cca12cf0276c",
-      "14aa70be-6b53-eeae-404a-1d76fe64af12",
-      "116959b7-9b6c-6916-5636-ec1d7a2d0e4b",
-      "91bea27e-6e3c-f27c-379b-8950efac29ae",
-      "6bb8c93a-708e-6860-3837-4e590fb55354"
-   ],
-   "owner":0,
-   "sharedWithTeam":false,
-   "synced":false,
-   "subscribed":false,
-   "hasRequests":true,
-   "requests":[
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"116959b7-9b6c-6916-5636-ec1d7a2d0e4b",
-         "name":"Create Specific Config Termination Point",
-         "description":"This restconf request creates port/interface and attach it to specific bridge. Using ovsdb:option, you can pass the optional input to port/interface create optional. E.g. remote_ip=xx.xx.xx.xx.",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
-         "method":"PUT",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\nAccept: application/json\n",
-         "data":"{\n  \"network-topology:termination-point\": [\n    \t{\n  \t\t\t\"ovsdb:options\": [\n    \t\t\t{\n                  \"ovsdb:option\": \"remote_ip\",\n                  \"ovsdb:value\" : \"10.10.11.11\"\n\t\t    \t}\n\t  \t\t],\n\t  \t\t\"ovsdb:name\": \"vxlanport\",\n\t  \t\t\"ovsdb:bridge-name\": \"brtest\",\n          \t\"ovsdb:interface-type\": \"ovsdb:interface-type-vxlan\",\n  \t\t\t\"tp-id\": \"vxlanport\",\n            \"vlan-tag\": \"1\",\n            \"trunks\": [\n                {\n                    \"trunk\": \"2\"\n                },\n                {\n                    \"trunk\": \"3\"\n                }\n            ],\n            \"ovsdb:attached-to\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='ovsdb://10.10.10.10:22222/bridge/brtest']\"\n\n\t\t}\n    ]\n}",
-         "dataMode":"raw",
-         "timestamp":0,
-         "version":2,
-         "time":1428002858175
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"14aa70be-6b53-eeae-404a-1d76fe64af12",
-         "name":"Get Specific Config OvsdbNode",
-         "description":"This restconf request fetch the configuration for specific node (ovsdb node or bridge node)",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
-         "method":"GET",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"6bb8c93a-708e-6860-3837-4e590fb55354",
-         "name":"Get Specific Config Termination Point",
-         "description":"Fetch configuration for specific termination point of the bridge from config data store.",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
-         "method":"GET",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"84c5f57e-14aa-a096-0a23-193828da309c",
-         "name":"Delete Specific Config OvsdbNode",
-         "description":"This restconf request delete any node (ovsdb node or bridge node) from the config data store. You can use the same request to delete the ovsdb node by using the following URI: http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
-         "method":"DELETE",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"91bea27e-6e3c-f27c-379b-8950efac29ae",
-         "name":"Delete Specific ConfigTermination Point",
-         "description":"Delete configuration of specified termination point of bridge. ",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
-         "method":"DELETE",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"96457d05-3f7d-981b-cf11-c9260b4b9391",
-         "name":"Create Specific Config OvsdbNode",
-         "description":"Fire this Restconf request if you want to initiate the connection to ovsdb node from controller. It assumes that ovsdb node is listening for tcp connection in passive mode. To configure the ovsdb node for listening incoming connection, please fire following command at ovsdb node machine\n\n\"ovs-vsctl set-manager tcp:16640\"",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:16640",
-         "method":"PUT",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
-         "data":"{\n  \"network-topology:node\": [\n        {\n            \"node-id\": \"ovsdb://10.10.10.10:16640\",\n            \"ovsdb:port\": 16640,\n            \"ovsdb:ip\": \"10.10.10.10\"\n        }\n    ]\n}",
-         "dataMode":"raw",
-         "timestamp":0,
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"beb434cf-7f69-83a5-d1f3-cca12cf0276c",
-         "name":"Get Config Topology",
-         "description":"Fetch the config topology from configuration data store.",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/",
-         "method":"GET",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "responses":[
-
-         ],
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"c7d7ac50-215a-2014-49c5-99791c494797",
-         "name":"Get Operational Topology",
-         "description":"This restconf request will fetch the operational topology. Operational topology details are fetch by southbound plugin from all the connected ovsdb node.",
-         "url":"http://localhost:8080/restconf/operational/network-topology:network-topology/",
-         "method":"GET",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
-         "data":[
-
-         ],
-         "dataMode":"params",
-         "timestamp":0,
-         "responses":[
-
-         ],
-         "version":2
-      },
-      {
-         "collectionId":"fe7da84a-d1cf-ef3e-fa5c-fd59771ea897",
-         "id":"dba73a23-c978-718e-d671-29cbb23935fd",
-         "name":"Create Specific Config Bridge",
-         "description":"This restconf request creates bridge on the specified ovsdb node.   Restconf URI contains node-id and this node-id has ip address and port. To determine the ip address and port information, fire \"Get Operational Topology\" restconf request and search for node where you want to create a bridge and then use the ip-address / port details from that output. Once you find out the ip-address/port, update the node-id and ovsdb:managed-by element in the restconf body.\n\n       Note: these %2F ('/') in the url are not there by mistake, those are there intentionally because node-id can contain '/'.\n\n    Note:Bridge name should not contain '-' in it, If you bridge name will contain '-', bridge creation will fail. It's know bug and under investigation.",
-         "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
-         "method":"PUT",
-         "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
-         "data":"{\n  \"network-topology:node\": [\n        {\n            \"node-id\": \"ovsdb://10.10.10.10:22222/bridge/brtest\",\n             \"ovsdb:bridge-name\": \"brtest\",\n             \"ovsdb:datapath-id\": \"00:00:b2:bf:48:25:f2:4b\",\n             \"ovsdb:protocol-entry\": [\n                {\n                  \"protocol\": \"ovsdb:ovsdb-bridge-protocol-openflow-13\"\n                }\n              ],\n              \"ovsdb:controller-entry\": [\n                {\n                  \"target\": \"tcp:11.11.11.11:6633\"\n                }\n              ],\n             \"ovsdb:managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='ovsdb://10.10.10.10:22222']\"\n        }\n    ]\n}",
-         "dataMode":"raw",
-         "timestamp":0,
-         "version":2
-      }
-   ]
+{    "id":"7969e460-82a6-c628-3921-c8b2f833cf20",
+    "name":"Ovsdb Southbound Collection",
+    "timestamp":1424977469540,
+    "order":[        "d358f955-9aaa-35a4-0f05-e0e817d19fae",
+        "1a877c07-3c4e-5fa3-baa1-517d650e566f",
+        "0408246c-2f84-8cbd-3448-4da85c92c819",
+        "375116bc-3c00-ce41-766f-7670a4b5645b",
+        "ea3557d2-68ab-d3a3-9ed5-b7bf59c45cc5",
+        "2e6a0928-ebf5-63ca-5db6-23a85bf85e5f",
+        "997fc659-ba78-2621-9b7b-7b57f428fb1e",
+        "a01f6148-a8fd-e579-de7b-79fb490fa001",
+        "5e0fc988-e250-55d1-4411-fceabb459b3a"
+    ],
+    "owner":0,
+    "sharedWithTeam":false,
+    "synced":false,
+    "subscribed":false,
+    "hasRequests":true,
+    "requests":[        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"0408246c-2f84-8cbd-3448-4da85c92c819",
+            "name":"Create Specific Config Bridge",
+            "description":"This restconf request creates bridge on the specified ovsdb node.   Restconf URI contains node-id and this node-id has ip address and port. To determine the ip address and port information, fire \"Get Operational Topology\" restconf request and search for node where you want to create a bridge and then use the ip-address / port details from that output. Once you find out the ip-address/port, update the node-id and ovsdb:managed-by element in the restconf body.\n\n       Note: these %2F ('/') in the url are not there by mistake, those are there intentionally because node-id can contain '/'.\n\n    Note:Bridge name should not contain '-' in it, If you bridge name will contain '-', bridge creation will fail. It's know bug and under investigation.",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
+            "method":"PUT",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "data":"{\n  \"network-topology:node\": [\n        {\n            \"node-id\": \"ovsdb://10.10.10.10:22222/bridge/brtest\",\n             \"ovsdb:bridge-name\": \"brtest\",\n             \"ovsdb:datapath-id\": \"00:00:b2:bf:48:25:f2:4b\",\n             \"ovsdb:protocol-entry\": [\n                {\n                  \"protocol\": \"ovsdb:ovsdb-bridge-protocol-openflow-13\"\n                }\n              ],\n              \"ovsdb:controller-entry\": [\n                {\n                  \"target\": \"tcp:11.11.11.11:6633\"\n                }\n              ],\n             \"ovsdb:managed-by\": \"/network-topology:network-topology/network-topology:topology[network-topology:topology-id='ovsdb:1']/network-topology:node[network-topology:node-id='ovsdb://10.10.10.10:22222']\"\n        }\n    ]\n}",
+            "dataMode":"raw",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"1a877c07-3c4e-5fa3-baa1-517d650e566f",
+            "name":"Get Operational Topology",
+            "description":"This restconf request will fetch the operational topology. Operational topology details are fetch by southbound plugin from all the connected ovsdb node.",
+            "url":"http://localhost:8080/restconf/operational/network-topology:network-topology/",
+            "method":"GET",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "responses":[
+            ],
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"2e6a0928-ebf5-63ca-5db6-23a85bf85e5f",
+            "name":"Get Specific Config OvsdbNode",
+            "description":"This restconf request fetch the configuration for specific node (ovsdb node or bridge node)",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
+            "method":"GET",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"375116bc-3c00-ce41-766f-7670a4b5645b",
+            "name":"Delete Specific Config OvsdbNode",
+            "description":"This restconf request delete any node (ovsdb node or bridge node) from the config data store. You can use the same request to delete the ovsdb node by using the following URI: http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest",
+            "method":"DELETE",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"5e0fc988-e250-55d1-4411-fceabb459b3a",
+            "name":"Get Specific Config Termination Point",
+            "description":"Fetch configuration for specific termination point of the bridge from config data store.",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
+            "method":"GET",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"997fc659-ba78-2621-9b7b-7b57f428fb1e",
+            "name":"Create Specific Config Termination Point",
+            "description":"This restconf request creates port/interface and attach it to specific bridge. Using ovsdb:option, you can pass the optional input to port/interface create optional. E.g. remote_ip=xx.xx.xx.xx.",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
+            "method":"PUT",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\nAccept: application/json\n",
+            "data":"{\n  \"network-topology:termination-point\": [\n    \t{\n  \t\t\t\"ovsdb:options\": [\n    \t\t\t{\n                  \"ovsdb:option\": \"remote_ip\",\n                  \"ovsdb:value\" : \"10.10.11.11\"\n\t\t    \t}\n\t  \t\t],\n\t  \t\t\"ovsdb:name\": \"vxlanport\",\n          \t\"ovsdb:interface-type\": \"ovsdb:interface-type-vxlan\",\n  \t\t\t\"tp-id\": \"vxlanport\",\n            \"vlan-tag\": \"1\",\n            \"trunks\": [\n                {\n                    \"trunk\": \"2\"\n                },\n                {\n                    \"trunk\": \"3\"\n                }\n            ],\n            \"vlan-mode\":\"access\"\n\t\t}\n    ]\n}",
+            "dataMode":"raw",
+            "timestamp":0,
+            "version":2,
+            "time":1428527877458
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"a01f6148-a8fd-e579-de7b-79fb490fa001",
+            "name":"Delete Specific ConfigTermination Point",
+            "description":"Delete configuration of specified termination point of bridge. ",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:22222%2Fbridge%2Fbrtest/termination-point/vxlanport/",
+            "method":"DELETE",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"d358f955-9aaa-35a4-0f05-e0e817d19fae",
+            "name":"Create Specific Config OvsdbNode",
+            "description":"Fire this Restconf request if you want to initiate the connection to ovsdb node from controller. It assumes that ovsdb node is listening for tcp connection in passive mode. To configure the ovsdb node for listening incoming connection, please fire following command at ovsdb node machine\n\n\"ovs-vsctl set-manager tcp:16640\"",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/topology/ovsdb:1/node/ovsdb:%2F%2F10.10.10.10:16640",
+            "method":"PUT",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+            "data":"{\n  \"network-topology:node\": [\n        {\n            \"node-id\": \"ovsdb://10.10.10.10:16640\",\n            \"ovsdb:port\": 16640,\n            \"ovsdb:ip\": \"10.10.10.10\"\n        }\n    ]\n}",
+            "dataMode":"raw",
+            "timestamp":0,
+            "version":2
+        },
+        {            "collectionId":"7969e460-82a6-c628-3921-c8b2f833cf20",
+            "id":"ea3557d2-68ab-d3a3-9ed5-b7bf59c45cc5",
+            "name":"Get Config Topology",
+            "description":"Fetch the config topology from configuration data store.",
+            "url":"http://localhost:8080/restconf/config/network-topology:network-topology/",
+            "method":"GET",
+            "headers":"Authorization: Basic YWRtaW46YWRtaW4=\n",
+            "data":[
+            ],
+            "dataMode":"params",
+            "timestamp":0,
+            "responses":[
+            ],
+            "version":2
+        }
+    ]
 }
\ No newline at end of file