Merge "Use ${project.version} for internal dependencies"
[ovsdb.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / NeutronCacheUtilsTest.java
1 /*
2  * Copyright (c) 2015, 2016 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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
14
15 import java.util.AbstractMap;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.junit.Test;
21 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
22 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
23 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSubnet;
24 import org.opendaylight.ovsdb.openstack.netvirt.translator.Neutron_IPs;
25 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronNetworkCRUD;
26 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronPortCRUD;
27 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronSubnetCRUD;
28
29 /**
30  * Unit test for {@link NeutronCacheUtils}
31  */
32 public class NeutronCacheUtilsTest {
33
34     /**
35      * Test method {@link NeutronCacheUtils#getMacAddress(INeutronPortCRUD, String, String)}
36      */
37     @Test
38     public void testGetMacAddress(){
39         INeutronPortCRUD neutronPortsCache = mock(INeutronPortCRUD.class);
40         NeutronPort port = mock(NeutronPort.class);
41         Neutron_IPs ip = mock(Neutron_IPs.class);
42         when(ip.getIpAddress()).thenReturn("ip_address");
43         when(ip.getSubnetUUID()).thenReturn("subnetUUID");
44         List<Neutron_IPs> list_fixedIP = new ArrayList<>();
45         list_fixedIP.add(ip);
46         when(port.getFixedIPs()).thenReturn(list_fixedIP);
47         when(port.getMacAddress()).thenReturn("mac_address");
48         List<NeutronPort> list_port = new ArrayList<>();
49         list_port.add(port);
50
51         when(neutronPortsCache.getAllPorts()).thenReturn(list_port);
52
53         assertEquals("Error, getMacAddress() did not return the correct value", "mac_address", NeutronCacheUtils.getMacAddress(neutronPortsCache, "subnetUUID", "ip_address"));
54     }
55
56     /**
57      * Test method {@link NeutronCacheUtils#getProviderInformation(INeutronNetworkCRUD, INeutronSubnetCRUD, String)}
58      */
59     @Test
60     public void testGetProviderInformation() {
61         INeutronSubnetCRUD neutronSubnetCache = mock(INeutronSubnetCRUD.class);
62         NeutronSubnet subnet = mock(NeutronSubnet.class);
63         when(subnet.getID()).thenReturn("subnetUUID");
64         when(subnet.getNetworkUUID()).thenReturn("networkUUID");
65         List<NeutronSubnet> list_subnet = new ArrayList<>();
66         list_subnet.add(subnet);
67
68         when(neutronSubnetCache.getAllSubnets()).thenReturn(list_subnet );
69
70         INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
71         NeutronNetwork network = mock(NeutronNetwork.class);
72         when(network.getID()).thenReturn("networkUUID");
73         when(network.getProviderNetworkType()).thenReturn("network_type_1");
74         when(network.getProviderSegmentationID()).thenReturn("network_segID");
75         List<NeutronNetwork> list_network = new ArrayList<>();
76         list_network.add(network);
77
78         when(neutronNetworkCache.getAllNetworks()).thenReturn(list_network);
79
80         Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<>(
81                 network.getProviderNetworkType(), network.getProviderSegmentationID());
82
83         assertEquals("Error, getProviderInformation() did not return the correct values", entry, NeutronCacheUtils.getProviderInformation(neutronNetworkCache, neutronSubnetCache, "subnetUUID"));
84     }
85 }