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;
22 import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
23 import org.opendaylight.ovsdb.plugin.impl.ConfigurationServiceImpl;
24 import org.opendaylight.ovsdb.plugin.impl.ConnectionServiceImpl;
25 import org.opendaylight.ovsdb.plugin.impl.InventoryServiceImpl;
27 public abstract class PluginTestBase {
28 private final static String identifier = "TEST";
29 protected final static String BRIDGE_NAME = "JUNIT_TEST_BRIDGE";
30 protected final static String PORT_NAME = "test0";
31 protected final static String TAGGED_PORT_NAME = "test1";
32 protected final static String TUNNEL_PORT_NAME = "vxlan0";
33 protected final static String FAKE_IP = "192.168.254.254";
34 private final static String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
35 private final static String SERVER_PORT = "ovsdbserver.port";
36 private final static String DEFAULT_SERVER_PORT = "6640";
38 public Properties loadProperties() throws IOException {
39 Properties props = new Properties(System.getProperties());
43 public class TestObjects {
44 public final ConnectionServiceImpl connectionService;
45 public final InventoryServiceImpl inventoryService;
46 public final ConfigurationServiceImpl configurationService;
47 public final Node node;
49 public TestObjects(ConnectionServiceImpl connectionService, Node node, InventoryServiceImpl inventoryService, ConfigurationServiceImpl configurationService) {
50 this.connectionService = connectionService;
51 this.inventoryService = inventoryService;
52 this.configurationService = configurationService;
57 public TestObjects getTestConnection() throws IOException {
58 if (OvsdbPluginTestSuiteIT.getTestObjects() != null) {
59 return OvsdbPluginTestSuiteIT.getTestObjects();
61 Properties props = loadProperties();
62 String address = props.getProperty(SERVER_IPADDRESS);
63 String port = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
65 if (address == null) {
66 Assert.fail("Usage : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify");
69 Node.NodeIDType.registerIDType("OVS", String.class);
70 NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class,
72 InventoryServiceImpl inventoryService = new InventoryServiceImpl();
73 inventoryService.init();
75 ConnectionServiceImpl connectionService = new ConnectionServiceImpl();
76 connectionService.init();
77 InventoryServiceImpl inventory = new InventoryServiceImpl();
79 connectionService.setOvsdbInventoryService(inventory);
80 connectionService.setOvsdbConnection(OvsdbConnectionService.getService());
81 ConfigurationServiceImpl configurationService = new ConfigurationServiceImpl();
82 configurationService.setConnectionServiceInternal(connectionService);
83 configurationService.setOvsdbInventoryService(inventory);
84 inventory.setOvsdbConfigurationService(configurationService);
86 Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
88 params.put(ConnectionConstants.ADDRESS, address);
89 params.put(ConnectionConstants.PORT, port);
91 Node node = connectionService.connect(identifier, params);
93 throw new IOException("Failed to connect to the ovsdb server");
98 } catch (InterruptedException e) {
99 // TODO Auto-generated catch block
102 TestObjects testObject = new TestObjects(connectionService, node, inventory, configurationService);
103 OvsdbPluginTestSuiteIT.setTestObjects(testObject);