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.*;
15 import static org.mockito.Mockito.*;
16 import static org.mockito.Matchers.any;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
21 import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
22 import org.powermock.api.mockito.PowerMockito;
23 import org.powermock.modules.junit4.PowerMockRunner;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
26 import org.opendaylight.controller.sal.core.Node;
27 import org.opendaylight.ovsdb.plugin.ConfigurationService;
28 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
29 import org.opendaylight.controller.sal.utils.ServiceHelper;
31 import java.net.InetAddress;
32 import java.util.HashMap;
35 import org.opendaylight.ovsdb.lib.table.internal.Table;
37 @RunWith(PowerMockRunner.class)
38 @PrepareForTest(ServiceHelper.class)
39 public class AdminConfigManagerTest {
41 public void testPopulateTunnelEndpoint() throws Exception {
42 InetAddress testAddress = InetAddress.getByName("10.10.10.10");
44 Node mockNode = mock(Node.class);
46 Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
48 Open_vSwitch ovsTable = new Open_vSwitch();
49 OvsDBMap localIp = new OvsDBMap();
50 localIp.put("local_ip", "10.10.10.10");
51 ovsTable.setOther_config(localIp);
52 ovsMap.put("Open_vSwitch", ovsTable);
54 OVSDBConfigService ovsdbConfig = mock(ConfigurationService.class);
55 when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
57 PowerMockito.mockStatic(ServiceHelper.class);
58 when(ServiceHelper.getGlobalInstance(eq(OVSDBConfigService.class), anyObject())).thenReturn(ovsdbConfig);
60 AdminConfigManager.getManager().populateTunnelEndpoint(mockNode);
62 assertEquals(testAddress, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));