Merge remote-tracking branch 'origin/master' into merge-branch
[netvirt.git] / plugin / src / test / java / org / opendaylight / ovsdb / plugin / OvsdbTestBase.java
similarity index 75%
rename from ovsdb/src/test/java/org/opendaylight/ovsdb/plugin/OvsdbTestBase.java
rename to plugin/src/test/java/org/opendaylight/ovsdb/plugin/OvsdbTestBase.java
index 3bdbefbcc300cba31d031f2af516c0aaeafdd29c..e9644dbcd81683422c10408f2e1559be3dd31bca 100644 (file)
 package org.opendaylight.ovsdb.plugin;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
+import junit.framework.Assert;
+
 import org.opendaylight.controller.sal.connection.ConnectionConstants;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -26,19 +27,12 @@ public abstract class OvsdbTestBase {
     protected final static String TAGGED_PORT_NAME = "eth1";
     protected final static String TUNNEL_PORT_NAME = "vxlan0";
     protected final static String FAKE_IP = "192.168.254.254";
+    private final static String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
+    private final static String SERVER_PORT = "ovsdbserver.port";
+    private final static String DEFAULT_SERVER_PORT = "6640";
 
     public Properties loadProperties() throws IOException {
-        InputStream is = this
-                .getClass()
-                .getClassLoader()
-                .getResourceAsStream(
-                        "org/opendaylight/ovsdb/lib/message/integration-test.properties");
-        if (is == null) {
-            throw new IOException("Unable to load integration-test.properties");
-        }
-        Properties props = new Properties();
-        props.load(is);
-
+        Properties props = new Properties(System.getProperties());
         return props;
     }
 
@@ -55,9 +49,19 @@ public abstract class OvsdbTestBase {
     }
 
     public TestObjects getTestConnection() throws IOException {
+        Properties props = loadProperties();
+        String address = props.getProperty(SERVER_IPADDRESS);
+        String port = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
+
+        if (address == null) {
+            Assert.fail("Usage : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify");
+        }
+
         Node.NodeIDType.registerIDType("OVS", String.class);
         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class,
                 "OVS");
+        InventoryService inventoryService = new InventoryService();
+        inventoryService.init();
 
         ConnectionService connectionService = new ConnectionService();
         connectionService.init();
@@ -65,11 +69,9 @@ public abstract class OvsdbTestBase {
         inventory.init();
         connectionService.setInventoryServiceInternal(inventory);
         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
-        Properties props = loadProperties();
-        params.put(ConnectionConstants.ADDRESS,
-                props.getProperty("ovsdbserver.ipaddress"));
-        params.put(ConnectionConstants.PORT,
-                props.getProperty("ovsdbserver.port", "6640"));
+
+        params.put(ConnectionConstants.ADDRESS, address);
+        params.put(ConnectionConstants.PORT, port);
 
         Node node = connectionService.connect(identifier, params);
         if (node == null) {