2 * [[ Authors will Fill in the Copyright header ]]
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
8 * Authors : Brent Salisbury, Hugo Trippaers
10 package org.opendaylight.ovsdb.plugin;
12 import java.io.IOException;
13 import java.util.HashMap;
15 import java.util.Properties;
17 import junit.framework.Assert;
19 import org.opendaylight.controller.sal.connection.ConnectionConstants;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.core.NodeConnector;
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";
29 public Properties loadProperties() throws IOException {
30 Properties props = new Properties(System.getProperties());
34 public class TestObjects {
35 public final ConnectionService connectionService;
36 public final Node node;
38 public TestObjects(ConnectionService connectionService, Node node) {
39 this.connectionService = connectionService;
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);
49 if (address == null) {
50 Assert.fail("Usage : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify");
53 Node.NodeIDType.registerIDType("OVS", String.class);
54 NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class,
56 InventoryService inventoryService = new InventoryService();
57 inventoryService.init();
59 ConnectionService connectionService = new ConnectionService();
60 connectionService.init();
62 connectionService.setInventoryServiceInternal(inventoryService);
63 Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
65 params.put(ConnectionConstants.ADDRESS, address);
66 params.put(ConnectionConstants.PORT, port);
68 Node node = connectionService.connect(identifier, params);
70 throw new IOException("Failed to connecto to ovsdb server");
72 return new TestObjects(connectionService, node);