Merge "Added Mockito and PowerMock to the neutron pom.xml Unit test coverage for...
[netvirt.git] / neutron / src / test / java / org / opendaylight / ovsdb / neutron / AdminConfigManagerTest.java
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
7  *
8  * Contributors:
9  *    Dave Tucker (HP) - Added unit tests for the AdminConfigManager class.
10  *******************************************************************************/
11
12 package org.opendaylight.ovsdb.neutron;
13
14 import static org.junit.Assert.*;
15 import static org.mockito.Mockito.*;
16 import static org.mockito.Matchers.any;
17
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;
25
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;
30
31 import java.net.InetAddress;
32 import java.util.HashMap;
33 import java.util.Map;
34
35 import org.opendaylight.ovsdb.lib.table.internal.Table;
36
37 @RunWith(PowerMockRunner.class)
38 @PrepareForTest(ServiceHelper.class)
39 public class AdminConfigManagerTest {
40     @Test
41     public void testPopulateTunnelEndpoint() throws Exception {
42         InetAddress testAddress = InetAddress.getByName("10.10.10.10");
43
44         Node mockNode = mock(Node.class);
45
46         Map<String, Table<?>> ovsMap = new HashMap<String, Table<?>>();
47
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);
53
54         OVSDBConfigService ovsdbConfig = mock(ConfigurationService.class);
55         when(ovsdbConfig.getRows(any(Node.class), anyString())).thenReturn(ovsMap);
56
57         PowerMockito.mockStatic(ServiceHelper.class);
58         when(ServiceHelper.getGlobalInstance(eq(OVSDBConfigService.class), anyObject())).thenReturn(ovsdbConfig);
59
60         AdminConfigManager.getManager().populateTunnelEndpoint(mockNode);
61
62         assertEquals(testAddress, AdminConfigManager.getManager().getTunnelEndPoint(mockNode));
63     }
64 }