Merge "Revert "Added controller is-connected code""
[netvirt.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / impl / ConfigurationServiceImplTest.java
1 /*
2  * Copyright (c) 2015 Inocybe and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.ovsdb.openstack.netvirt.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyString;
13 import static org.mockito.Matchers.same;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17 import java.util.HashMap;
18 import java.util.Map;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentMap;
21
22 import org.junit.*;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
27 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
30 import org.powermock.api.mockito.PowerMockito;
31 import org.powermock.core.classloader.annotations.PrepareForTest;
32 import org.powermock.modules.junit4.PowerMockRunner;
33
34 /**
35  * Unit test for {@link ConfigurationServiceImpl}
36  */
37 @Ignore // TODO SB_MIGRATION
38 @PrepareForTest(ConfigProperties.class)
39 @RunWith(PowerMockRunner.class)
40 public class ConfigurationServiceImplTest {
41
42     @InjectMocks
43     private ConfigurationServiceImpl configurationServiceImpl;
44
45     private static final String HOST_ADDRESS = "127.0.0.1";
46
47     /**
48      * Test method {@link ConfigurationServiceImpl#getTunnelEndPoint(Node)}
49      */
50     @Test
51     public void testGetTunnelEndPoint() throws Exception {
52         //Row row = mock(Row.class);
53         //ConcurrentMap<String, Row> ovsTable = new ConcurrentHashMap();
54         //ovsTable.put("key", row);
55
56         //OpenVSwitch ovsRow = mock(OpenVSwitch.class);
57         Map<String, String> configs = new HashMap();
58         configs.put(Constants.TUNNEL_ENDPOINT_KEY, HOST_ADDRESS);
59         //Column<GenericTableSchema, Map<String, String>> otherConfigColumn = mock(Column.class);
60
61         //when(ovsRow.getOtherConfigColumn()).thenReturn(otherConfigColumn);
62         //when(otherConfigColumn.getData()).thenReturn(configs);
63
64         /* TODO SB_MIGRATION */
65         //when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(ovsTable);
66         //when(ovsdbConfigurationService.getTypedRow(any(Node.class),same(OpenVSwitch.class), any(Row.class))).thenReturn(ovsRow);
67
68         //assertEquals("Error, did not return address of tunnelEndPoint", HOST_ADDRESS, configurationServiceImpl.getTunnelEndPoint(mock(Node.class)).getHostAddress());
69     }
70
71     /**
72      * Test method {@link ConfigurationServiceImpl#getDefaultGatewayMacAddress(Node)}
73      */
74     @Test
75     public void testGetDefaultGatewayMacAddress(){
76         Node node = mock(Node.class);
77         NodeId nodeId = mock(NodeId.class);
78         PowerMockito.mockStatic(ConfigProperties.class);
79
80         when(node.getNodeId()).thenReturn(nodeId);
81         when(nodeId.getValue()).thenReturn("nodeIdValue");
82         PowerMockito.when(ConfigProperties.getProperty(configurationServiceImpl.getClass(),
83                 "ovsdb.l3gateway.mac." + node.getNodeId().getValue())).thenReturn("gateway");
84
85         assertEquals("Error, did not return the defaultGatewayMacAddress of the node", "gateway",
86                 configurationServiceImpl.getDefaultGatewayMacAddress(node));
87     }
88 }