Remove plugin dependencies
[ovsdb.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.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.opendaylight.ovsdb.lib.notation.Column;
27 import org.opendaylight.ovsdb.lib.notation.Row;
28 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
29 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
30 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
31 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
34 import org.powermock.api.mockito.PowerMockito;
35 import org.powermock.core.classloader.annotations.PrepareForTest;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 /**
39  * Unit test for {@link ConfigurationServiceImpl}
40  */
41 @PrepareForTest(ConfigProperties.class)
42 @RunWith(PowerMockRunner.class)
43 public class ConfigurationServiceImplTest {
44
45     @InjectMocks
46     private ConfigurationServiceImpl configurationServiceImpl;
47
48     private static final String HOST_ADDRESS = "127.0.0.1";
49
50     /**
51      * Test method {@link ConfigurationServiceImpl#getTunnelEndPoint(Node)}
52      */
53     @Test
54     public void testGetTunnelEndPoint() throws Exception {
55         Row row = mock(Row.class);
56         ConcurrentMap<String, Row> ovsTable = new ConcurrentHashMap();
57         ovsTable.put("key", row);
58
59         OpenVSwitch ovsRow = mock(OpenVSwitch.class);
60         Map<String, String> configs = new HashMap();
61         configs.put(Constants.TUNNEL_ENDPOINT_KEY, HOST_ADDRESS);
62         Column<GenericTableSchema, Map<String, String>> otherConfigColumn = mock(Column.class);
63
64         when(ovsRow.getOtherConfigColumn()).thenReturn(otherConfigColumn);
65         when(otherConfigColumn.getData()).thenReturn(configs);
66
67         /* TODO SB_MIGRATION */
68         //when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(ovsTable);
69         //when(ovsdbConfigurationService.getTypedRow(any(Node.class),same(OpenVSwitch.class), any(Row.class))).thenReturn(ovsRow);
70
71         //assertEquals("Error, did not return address of tunnelEndPoint", HOST_ADDRESS, configurationServiceImpl.getTunnelEndPoint(mock(Node.class)).getHostAddress());
72     }
73
74     /**
75      * Test method {@link ConfigurationServiceImpl#getDefaultGatewayMacAddress(Node)}
76      */
77     @Test
78     public void testGetDefaultGatewayMacAddress(){
79         Node node = mock(Node.class);
80         NodeId nodeId = mock(NodeId.class);
81         PowerMockito.mockStatic(ConfigProperties.class);
82
83         when(node.getId()).thenReturn(nodeId);
84         when(nodeId.getValue()).thenReturn("nodeIdValue");
85         PowerMockito.when(ConfigProperties.getProperty(configurationServiceImpl.getClass(), "ovsdb.l3gateway.mac." + node.getId().getValue())).thenReturn("gateway");
86
87         assertEquals("Error, did not return the defaultGatewayMacAddress of the node", "gateway", configurationServiceImpl.getDefaultGatewayMacAddress(node));
88     }
89 }