1 /*******************************************************************************
2 * Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Dave Tucker (HP) - Added unit tests for the AdminConfigManager class.
10 *******************************************************************************/
12 package org.opendaylight.ovsdb.neutron;
14 import static org.junit.Assert.assertEquals;
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Matchers.anyObject;
17 import static org.mockito.Matchers.anyString;
18 import static org.mockito.Matchers.eq;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.when;
22 import java.net.InetAddress;
23 import java.util.HashMap;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.opendaylight.controller.sal.core.Node;
29 import org.opendaylight.controller.sal.utils.ServiceHelper;
30 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
31 import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
32 import org.opendaylight.ovsdb.lib.table.internal.Table;
33 import org.opendaylight.ovsdb.plugin.ConfigurationService;
34 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
39 @RunWith(PowerMockRunner.class)
40 @PrepareForTest(ServiceHelper.class)
41 public class AdminConfigManagerTest {
44 public void testGetTunnelEndpoint() throws Exception {
45 InetAddress testAddress = InetAddress.getByName("10.10.10.10");
47 Node mockNode = mock(Node.class);
49 Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
51 Open_vSwitch ovsTable = new Open_vSwitch();
52 OvsDBMap localIp = new OvsDBMap();
53 localIp.put("local_ip", "10.10.10.10");
54 ovsTable.setOther_config(localIp);
55 ovsMap.put("Open_vSwitch", ovsTable);
57 OVSDBConfigService ovsdbConfig = mock(ConfigurationService.class);
58 when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(null)
61 PowerMockito.mockStatic(ServiceHelper.class);
62 when(ServiceHelper.getGlobalInstance(eq(OVSDBConfigService.class), anyObject())).thenReturn(ovsdbConfig);
64 // OVSDBConfigService is null
65 assertEquals(null, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));
68 assertEquals(testAddress, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));
72 public void testGetTunnelEndpointWithNullRows() throws Exception {
73 InetAddress testAddress = InetAddress.getByName("10.10.10.10");
75 Node mockNode = mock(Node.class);
77 Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
79 Open_vSwitch nullRow = new Open_vSwitch();
80 Open_vSwitch ovsRow1 = new Open_vSwitch();
81 Open_vSwitch ovsRow2 = new Open_vSwitch();
82 OvsDBMap invalidLocalIp = new OvsDBMap();
83 OvsDBMap localIp = new OvsDBMap();
85 ovsRow1.setOther_config(invalidLocalIp);
87 localIp.put("local_ip","10.10.10.10");
88 ovsRow2.setOther_config(localIp);
90 ovsMap.put("0", nullRow);
91 ovsMap.put("1", ovsRow1);
92 ovsMap.put("2", ovsRow2);
94 OVSDBConfigService ovsdbConfig = mock(ConfigurationService.class);
95 when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
97 PowerMockito.mockStatic(ServiceHelper.class);
98 when(ServiceHelper.getGlobalInstance(eq(OVSDBConfigService.class), anyObject())).thenReturn(ovsdbConfig);
101 assertEquals(testAddress, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));