getNode fails when id contains | 69/15869/1
authorSam Hague <shague@redhat.com>
Sun, 1 Mar 2015 22:53:04 +0000 (17:53 -0500)
committerSam Hague <shague@redhat.com>
Sun, 1 Mar 2015 22:53:04 +0000 (17:53 -0500)
The split delimiter was not used correctly. The | is the OR operater so it needed to be escaped.

Also added getNode unit test

Change-Id: I94623198e1ab10ea6b37ec05f09196e6a298ac0e
Signed-off-by: Sam Hague <shague@redhat.com>
plugin/src/main/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImpl.java
plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java [new file with mode: 0644]

index a7625941151144b09b0b562533bc50c0b01a88ea..b4d80b2bc93c86c441771e0e76f5d1c7eed9cefa 100644 (file)
@@ -65,6 +65,10 @@ public class ConnectionServiceImpl implements OvsdbConnectionService,
     private static final String OVSDB_LISTENPORT = "ovsdb.listenPort";
 
 
+    public void putOvsdbConnection (String identifier, Connection connection) {
+        ovsdbConnections.put(identifier, connection);
+    }
+
     private ConcurrentMap<String, Connection> ovsdbConnections = new ConcurrentHashMap<String, Connection>();
     private List<ChannelHandler> handlers = null;
 
@@ -185,7 +189,7 @@ public class ConnectionServiceImpl implements OvsdbConnectionService,
     public Node getNode (String identifier) {
         String id = identifier;
 
-        String[] pair = identifier.split("[|,:]+");
+        String[] pair = identifier.split("\\|");
         if (pair[0].equals("OVS")) {
             id = pair[1];
         }
diff --git a/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java b/plugin/src/test/java/org/opendaylight/ovsdb/plugin/impl/ConnectionServiceImplTest.java
new file mode 100644 (file)
index 0000000..815a068
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (C) 2015 Red Hat, Inc.
+ *
+ *  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
+ *
+ *  Authors : Sam Hague
+ */
+package org.opendaylight.ovsdb.plugin.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.ovsdb.plugin.api.Connection;
+
+public class ConnectionServiceImplTest {
+    private static final String OVS = "OVS";
+    private static final String IDENTIFIER = "192.168.120.31:45001";
+    private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER;
+    private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER;
+
+    @Test
+    public void testGetNode () {
+        Node.NodeIDType.registerIDType(OVS, String.class);
+        NodeConnector.NodeConnectorIDType.registerIDType(OVS, String.class, OVS);
+        ConnectionServiceImpl connectionService = new ConnectionServiceImpl();
+        Connection connection = new Connection(IDENTIFIER, null);
+        connectionService.putOvsdbConnection(IDENTIFIER, connection);
+
+        Node node = connectionService.getNode(IDENTIFIER);
+        assertNotNull("Node " + IDENTIFIER + " is null", node);
+
+        node = connectionService.getNode(OVS_IDENTIFIER);
+        assertNotNull("Node " + OVS_IDENTIFIER + " is null", node);
+
+        node = connectionService.getNode(IDENTIFIER + "extra");
+        assertNull("Node " + BAD_IDENTIFIER + " is not null", node);
+    }
+}