+ assertEquals(testAddress, adminConfigManager.getTunnelEndPoint(mockNode));
+ }
+
+ // Add key:value pairs to the map.
+ // Calling again with the same key will overwrite the current pair.
+ private void initMap (String key, String value) {
+ map.put(key, value);
+ ovsTable.setOther_config(map);
+ ovsMap.put(OPENVSWITCH, ovsTable);
+ }
+
+ @Test
+ public void testGetPhysicalInterfaceName () throws Exception {
+ when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
+
+ // Check if match can be found with a single pair
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1);
+ assertEquals("Failed to find " + ETH1 + " in " + map.toString(),
+ ETH1, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));
+
+ // Check if match can be found with different pairs
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2);
+ assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
+ ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
+
+ // Check if match can be found with duplicate pairs
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2 + "," + PHYSNET2 + ":" + ETH2);
+ assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
+ ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
+
+ // Check if match can be found with multiple pairs and extra other_config
+ initMap(LOCAL_IP, IPADDR);
+ assertEquals("Failed to find " + ETH2 + " in " + map.toString(),
+ ETH2, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET2));
+ }
+
+ @Test
+ public void testGetPhysicalInterfaceNameNegative () throws Exception {
+ when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(null)
+ .thenReturn(ovsMap);
+
+ // Add a null row, an empty row and a good row to the table
+ Open_vSwitch nullRow = new Open_vSwitch();
+ Open_vSwitch emptyRow = new Open_vSwitch();
+ OvsDBMap emptyProviderMap = new OvsDBMap();
+ emptyRow.setOther_config(emptyProviderMap);
+ ovsMap.put("0", nullRow);
+ ovsMap.put("1", emptyRow);
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1);
+
+ // Check if no rows/no table is handled
+ assertEquals("Failed to return null when ovsdb table is null",
+ null, adminConfigManager.getTunnelEndPoint(node));
+
+ // Check if the null and empty rows are ignored
+ System.out.println("map = " + map.toString());
+ System.out.println("ovsMap = " + ovsMap.toString());
+ assertEquals("Failed to find " + ETH1 + " in " + map.toString(),
+ ETH1, adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));
+
+ // Should not be able to find match
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + ":" + ETH1 + "," + PHYSNET2 + ":" + ETH2);
+ assertNull("Found " + ETH3 + " in " + map.toString(),
+ adminConfigManager.getPhysicalInterfaceName(node, PHYSNET3));
+
+ // Should not be able to find match with mal-formed values
+ initMap(PROVIDER_MAPPINGS, PHYSNET1 + "-" + ETH1);
+ assertNull("Found " + ETH1 + " in " + map.toString(),
+ adminConfigManager.getPhysicalInterfaceName(node, PHYSNET1));