From 0aa6d3363b9c4d6b8c07d9b73aa471e8e33bd9ca Mon Sep 17 00:00:00 2001 From: Flavio Fernandes Date: Tue, 31 Mar 2015 17:08:13 -0400 Subject: [PATCH] Revert: Revert "Add JUnit testing for ConfigurationServiceImpl class." MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This commit re-introduces commit eb362a3e296c10ad8ac7b5cb626cd2466f4d558b. The issue was a minor tweak missing in pom.xml, so that powermock would stop generating npe. Change-Id: I4b3b7aa6fa8a597a3d0d84e648e2c0dd21038c68 Signed-off-by: Flavio Fernandes Also-by: Alexis de Talhouët --- openstack/net-virt/pom.xml | 17 ++++ .../impl/ConfigurationServiceImplTest.java | 92 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ConfigurationServiceImplTest.java diff --git a/openstack/net-virt/pom.xml b/openstack/net-virt/pom.xml index b44b719e4..9790abd43 100644 --- a/openstack/net-virt/pom.xml +++ b/openstack/net-virt/pom.xml @@ -70,6 +70,23 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.mockito mockito-core + test + + + org.powermock + powermock-core + ${powermock.version} + test + + + org.powermock + powermock-module-junit4 + test + + + org.powermock + powermock-api-mockito + test junit diff --git a/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ConfigurationServiceImplTest.java b/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ConfigurationServiceImplTest.java new file mode 100644 index 000000000..d855ec9bc --- /dev/null +++ b/openstack/net-virt/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/impl/ConfigurationServiceImplTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Inocybe and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.openstack.netvirt.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opendaylight.ovsdb.lib.notation.Column; +import org.opendaylight.ovsdb.lib.notation.Row; +import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; +import org.opendaylight.ovsdb.openstack.netvirt.api.Constants; +import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService; +import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.opendaylight.ovsdb.utils.config.ConfigProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +/** + * Unit test for {@link ConfigurationServiceImpl} + */ +@PrepareForTest(ConfigProperties.class) +@RunWith(PowerMockRunner.class) +public class ConfigurationServiceImplTest { + + @Mock + private OvsdbConfigurationService ovsdbConfigurationService; + + @InjectMocks + private ConfigurationServiceImpl configurationServiceImpl; + + private static final String HOST_ADDRESS = "127.0.0.1"; + + /** + * Test method {@link ConfigurationServiceImpl#getTunnelEndPoint(Node)} + */ + @Test + public void testGetTunnelEndPoint() throws Exception { + Row row = mock(Row.class); + ConcurrentMap ovsTable = new ConcurrentHashMap(); + ovsTable.put("key", row); + + OpenVSwitch ovsRow = mock(OpenVSwitch.class); + Map configs = new HashMap(); + configs.put(Constants.TUNNEL_ENDPOINT_KEY, HOST_ADDRESS); + Column> otherConfigColumn = mock(Column.class); + + when(ovsRow.getOtherConfigColumn()).thenReturn(otherConfigColumn); + when(otherConfigColumn.getData()).thenReturn(configs); + + when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(ovsTable); + when(ovsdbConfigurationService.getTypedRow(any(Node.class),same(OpenVSwitch.class), any(Row.class))).thenReturn(ovsRow); + + assertEquals("Error, did not return address of tunnelEndPoint", HOST_ADDRESS, configurationServiceImpl.getTunnelEndPoint(mock(Node.class)).getHostAddress()); + } + + /** + * Test method {@link ConfigurationServiceImpl#getDefaultGatewayMacAddress(Node)} + */ + @Test + public void testGetDefaultGatewayMacAddress(){ + Node node = mock(Node.class); + NodeId nodeId = mock(NodeId.class); + PowerMockito.mockStatic(ConfigProperties.class); + + when(node.getId()).thenReturn(nodeId); + when(nodeId.getValue()).thenReturn("nodeIdValue"); + PowerMockito.when(ConfigProperties.getProperty(configurationServiceImpl.getClass(), "ovsdb.l3gateway.mac." + node.getId().getValue())).thenReturn("gateway"); + + assertEquals("Error, did not return the defaultGatewayMacAddress of the node", "gateway", configurationServiceImpl.getDefaultGatewayMacAddress(node)); + } +} -- 2.36.6