Add JUnit testing for NeutronCacheUtilsTest class. 65/17965/1
authorAlexis de Talhouët <adetalhouet@inocybe.com>
Wed, 8 Apr 2015 21:06:10 +0000 (17:06 -0400)
committerAlexis de Talhouët <adetalhouet@inocybe.com>
Wed, 8 Apr 2015 21:06:10 +0000 (17:06 -0400)
Change-Id: I5041913f0809618d13f498ac24952452a67752fe
Signed-off-by: Alexis de Talhouët <adetalhouet@inocybe.com>
openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtilsTest.java [new file with mode: 0644]

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"));
+    }
+}