2 * Copyright (C) 2015 Red Hat, Inc.
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
10 package org.opendaylight.ovsdb.plugin.impl;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertSame;
15 import static org.junit.Assert.fail;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.ovsdb.plugin.api.Connection;
22 public class ConnectionServiceImplTest {
23 private static final String OVS = "OVS";
24 private static final String IDENTIFIER = "192.168.120.31:45001";
25 private static final String OVS_IDENTIFIER = OVS + "|" + IDENTIFIER;
26 private static final String BAD_IDENTIFIER = "BAD" + "|" + IDENTIFIER;
27 private static ConnectionServiceImpl connectionService;
30 public static void setUp () {
31 connectionService = new ConnectionServiceImpl();
32 Connection connection = new Connection(IDENTIFIER, null);
33 connectionService.putOvsdbConnection(IDENTIFIER, connection);
37 public void testGetNode () {
38 Node node = connectionService.getNode(IDENTIFIER);
39 assertNotNull("Node " + IDENTIFIER + " is null", node);
41 node = connectionService.getNode(OVS_IDENTIFIER);
42 assertNotNull("Node " + OVS_IDENTIFIER + " is null", node);
44 node = connectionService.getNode(IDENTIFIER + "extra");
45 assertNull("Node " + BAD_IDENTIFIER + " is not null", node);
49 public void testGetConnection () {
50 Node node = connectionService.getNode(IDENTIFIER);
51 assertNotNull("Node " + IDENTIFIER + " is null", node);
53 Connection connection = connectionService.getConnection(node);
54 assertNotNull("Connection " + IDENTIFIER + " is null", connection);
57 connection = connectionService.getConnection(null);
58 fail("Expected a NullPointerException to be thrown");
59 } catch (NullPointerException e) {
60 assertSame(NullPointerException.class, e.getClass());