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 {
43 public void testPopulateTunnelEndpoint() throws Exception {
44 InetAddress testAddress = InetAddress.getByName("10.10.10.10");
46 Node mockNode = mock(Node.class);
48 Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
50 Open_vSwitch ovsTable = new Open_vSwitch();
51 OvsDBMap localIp = new OvsDBMap();
52 localIp.put("local_ip", "10.10.10.10");
53 ovsTable.setOther_config(localIp);
54 ovsMap.put("Open_vSwitch", ovsTable);
56 OVSDBConfigService ovsdbConfig = mock(ConfigurationService.class);
57 when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
59 PowerMockito.mockStatic(ServiceHelper.class);
60 when(ServiceHelper.getGlobalInstance(eq(OVSDBConfigService.class), anyObject())).thenReturn(ovsdbConfig);
62 AdminConfigManager.getManager().populateTunnelEndpoint(mockNode);
64 assertEquals(testAddress, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));