Removed the ovsdb subdirectory properly in lieu of the upcoming rebase with master
[netvirt.git] / plugin / src / test / java / org / opendaylight / ovsdb / plugin / OvsdbTestBase.java
1 /*
2  * [[ Authors will Fill in the Copyright header ]]
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Brent Salisbury, Hugo Trippaers
9  */
10 package org.opendaylight.ovsdb.plugin;
11
12 import java.io.IOException;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Properties;
16
17 import junit.framework.Assert;
18
19 import org.opendaylight.controller.sal.connection.ConnectionConstants;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.core.NodeConnector;
22
23 public abstract class OvsdbTestBase {
24     private final static String identifier = "TEST";
25     private final static String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
26     private final static String SERVER_PORT = "ovsdbserver.port";
27     private final static String DEFAULT_SERVER_PORT = "6640";
28
29     public Properties loadProperties() throws IOException {
30         Properties props = new Properties(System.getProperties());
31         return props;
32     }
33
34     public class TestObjects {
35         public final ConnectionService connectionService;
36         public final Node node;
37
38         public TestObjects(ConnectionService connectionService, Node node) {
39             this.connectionService = connectionService;
40             this.node = node;
41         }
42     }
43
44     public TestObjects getTestConnection() throws IOException {
45         Properties props = loadProperties();
46         String address = props.getProperty(SERVER_IPADDRESS);
47         String port = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
48
49         if (address == null) {
50             Assert.fail("Usage : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify");
51         }
52
53         Node.NodeIDType.registerIDType("OVS", String.class);
54         NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class,
55                 "OVS");
56         InventoryService inventoryService = new InventoryService();
57         inventoryService.init();
58
59         ConnectionService connectionService = new ConnectionService();
60         connectionService.init();
61
62         connectionService.setInventoryServiceInternal(inventoryService);
63         Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
64
65         params.put(ConnectionConstants.ADDRESS, address);
66         params.put(ConnectionConstants.PORT, port);
67
68         Node node = connectionService.connect(identifier, params);
69         if (node == null) {
70             throw new IOException("Failed to connecto to ovsdb server");
71         }
72         return new TestObjects(connectionService, node);
73     }
74
75 }