2 * Copyright (c) 2015 Inocybe and others. All rights reserved.
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
8 package org.opendaylight.ovsdb.openstack.netvirt.impl;
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;
17 import java.util.HashMap;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentMap;
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.plugin.api.OvsdbConfigurationService;
31 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
32 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
40 * Unit test for {@link ConfigurationServiceImpl}
42 @PrepareForTest(ConfigProperties.class)
43 @RunWith(PowerMockRunner.class)
44 public class ConfigurationServiceImplTest {
47 private OvsdbConfigurationService ovsdbConfigurationService;
50 private ConfigurationServiceImpl configurationServiceImpl;
52 private static final String HOST_ADDRESS = "127.0.0.1";
55 * Test method {@link ConfigurationServiceImpl#getTunnelEndPoint(Node)}
58 public void testGetTunnelEndPoint() throws Exception {
59 Row row = mock(Row.class);
60 ConcurrentMap<String, Row> ovsTable = new ConcurrentHashMap();
61 ovsTable.put("key", row);
63 OpenVSwitch ovsRow = mock(OpenVSwitch.class);
64 Map<String, String> configs = new HashMap();
65 configs.put(Constants.TUNNEL_ENDPOINT_KEY, HOST_ADDRESS);
66 Column<GenericTableSchema, Map<String, String>> otherConfigColumn = mock(Column.class);
68 when(ovsRow.getOtherConfigColumn()).thenReturn(otherConfigColumn);
69 when(otherConfigColumn.getData()).thenReturn(configs);
71 when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(ovsTable);
72 when(ovsdbConfigurationService.getTypedRow(any(Node.class),same(OpenVSwitch.class), any(Row.class))).thenReturn(ovsRow);
74 assertEquals("Error, did not return address of tunnelEndPoint", HOST_ADDRESS, configurationServiceImpl.getTunnelEndPoint(mock(Node.class)).getHostAddress());
78 * Test method {@link ConfigurationServiceImpl#getDefaultGatewayMacAddress(Node)}
81 public void testGetDefaultGatewayMacAddress(){
82 Node node = mock(Node.class);
83 NodeId nodeId = mock(NodeId.class);
84 PowerMockito.mockStatic(ConfigProperties.class);
86 when(node.getId()).thenReturn(nodeId);
87 when(nodeId.getValue()).thenReturn("nodeIdValue");
88 PowerMockito.when(ConfigProperties.getProperty(configurationServiceImpl.getClass(), "ovsdb.l3gateway.mac." + node.getId().getValue())).thenReturn("gateway");
90 assertEquals("Error, did not return the defaultGatewayMacAddress of the node", "gateway", configurationServiceImpl.getDefaultGatewayMacAddress(node));