Merge "Fix Bug 3663: Update netvirt.impl UT"
[netvirt.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / impl / NeutronL3AdapterTest.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
9 package org.opendaylight.ovsdb.openstack.netvirt.impl;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17 import java.lang.reflect.Field;
18 import java.lang.reflect.Method;
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
31 import org.opendaylight.neutron.spi.INeutronPortCRUD;
32 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
33 import org.opendaylight.neutron.spi.NeutronFloatingIP;
34 import org.opendaylight.neutron.spi.NeutronNetwork;
35 import org.opendaylight.neutron.spi.NeutronPort;
36 import org.opendaylight.neutron.spi.NeutronRouter;
37 import org.opendaylight.neutron.spi.NeutronRouter_Interface;
38 import org.opendaylight.neutron.spi.NeutronSubnet;
39 import org.opendaylight.neutron.spi.Neutron_IPs;
40 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
41 import org.opendaylight.ovsdb.openstack.netvirt.api.ArpProvider;
42 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
43 import org.opendaylight.ovsdb.openstack.netvirt.api.InboundNatProvider;
44 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
45 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
46 import org.opendaylight.ovsdb.openstack.netvirt.api.OutboundNatProvider;
47 import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
48 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
49 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
50 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
51 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
52 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
55 import org.osgi.framework.BundleContext;
56 import org.osgi.framework.ServiceReference;
57 import org.powermock.api.mockito.PowerMockito;
58 import org.powermock.core.classloader.annotations.PrepareForTest;
59 import org.powermock.modules.junit4.PowerMockRunner;
60
61 /**
62  * Unit test for {@link NeutronL3Adapter}
63  */
64 @PrepareForTest({ConfigProperties.class, ServiceHelper.class})
65 @RunWith(PowerMockRunner.class)
66 public class NeutronL3AdapterTest {
67
68     @InjectMocks private NeutronL3Adapter neutronL3Adapter;
69
70     @Mock private ConfigurationService configurationService;
71     @Mock private TenantNetworkManager tenantNetworkManager;
72     @Mock private INeutronNetworkCRUD neutronNetworkCache;
73     @Mock private INeutronSubnetCRUD neutronSubnetCache;
74     @Mock private INeutronPortCRUD neutronPortCache;
75     @Mock private NodeCacheManager nodeCacheManager;
76     @Mock private Southbound southbound;
77
78     @Mock private NeutronPort neutronPort;
79
80     private Set<String> inboundIpRewriteCache;
81     private Set<String> outboundIpRewriteCache;
82     private Set<String> inboundIpRewriteExclusionCache;
83     private Set<String> outboundIpRewriteExclusionCache;
84     private Set<String> routerInterfacesCache;
85     private Set<String> staticArpEntryCache;
86     private Set<String> l3ForwardingCache;
87     private Set<String> defaultRouteCache;
88     private Map<String, String> networkIdToRouterMacCache;
89     private Map<String, NeutronRouter_Interface> subnetIdToRouterInterfaceCache;
90
91     private static final String HOST_ADDRESS = "127.0.0.1";
92
93     @Before
94     public void setUp() throws Exception{
95         PowerMockito.mockStatic(ConfigProperties.class);
96         PowerMockito.when(ConfigProperties.getProperty(neutronL3Adapter.getClass(), "ovsdb.l3.fwd.enabled")).thenReturn("yes");
97
98         when(configurationService.isL3ForwardingEnabled()).thenReturn(true);
99
100         this.getMethod("initL3AdapterMembers").invoke(neutronL3Adapter);
101
102         this.getNeutronL3AdapterFields();
103         this.setUpVar();
104     }
105
106     @Test
107     public void test() {
108
109     }
110
111     private void getNeutronL3AdapterFields() throws Exception{
112         inboundIpRewriteCache = (Set<String>) getField("inboundIpRewriteCache");
113         outboundIpRewriteCache = (Set<String>) getField("outboundIpRewriteCache");
114         inboundIpRewriteExclusionCache = (Set<String>) getField("inboundIpRewriteExclusionCache");
115         outboundIpRewriteExclusionCache = (Set<String>) getField("outboundIpRewriteExclusionCache");
116         routerInterfacesCache = (Set<String>) getField("routerInterfacesCache");
117         staticArpEntryCache = (Set<String>) getField("staticArpEntryCache");
118         l3ForwardingCache = (Set<String>) getField("l3ForwardingCache");
119         defaultRouteCache = (Set<String>) getField("defaultRouteCache");
120         networkIdToRouterMacCache = (Map<String, String>) getField("networkIdToRouterMacCache");
121         subnetIdToRouterInterfaceCache = (Map<String, NeutronRouter_Interface>) getField("subnetIdToRouterInterfaceCache");
122     }
123
124     private void setUpVar(){
125         Neutron_IPs neutronIP = mock(Neutron_IPs.class);
126         NeutronRouter neutronRouter = mock(NeutronRouter.class);
127
128         NeutronSubnet neutronSubnet = mock(NeutronSubnet.class);
129         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
130         Node node = mock(Node.class);
131         NodeId nodeID = mock(NodeId.class);
132         // TODO SB_MIGRATION
133         //Row row = mock(Row.class);
134         //Bridge bridge = mock(Bridge.class);
135         Status status = mock(Status.class);
136
137         List<Neutron_IPs> list_neutronIP = new ArrayList<Neutron_IPs>();
138         list_neutronIP.add(neutronIP);
139
140         List<NeutronPort> list_neutronPort = new ArrayList<>();
141         list_neutronPort.add(neutronPort);
142
143         List<Node> list_nodes = new ArrayList<Node>();
144         list_nodes.add(node);
145
146         //ConcurrentMap<String, Row> rowMap = mock(ConcurrentMap.class);
147         //rowMap.put("key", row);
148
149         //Column<GenericTableSchema, Set<String>> bridgeColumnIds = mock(Column.class);
150         Set<String> dpids = new HashSet();
151         dpids.add("11111");
152
153         when(neutronPort.getFixedIPs()).thenReturn(list_neutronIP);
154         when(neutronPort.getPortUUID()).thenReturn("portUUID");
155         when(neutronPort.getTenantID()).thenReturn("tenantID");
156         when(neutronPort.getNetworkUUID()).thenReturn("networkUUID");
157         when(neutronPort.getMacAddress()).thenReturn("macAddress1").thenReturn("macAddress2");
158
159         when(neutronIP.getSubnetUUID()).thenReturn("subnetUUID");
160         when(neutronIP.getIpAddress()).thenReturn(HOST_ADDRESS);
161
162         when(neutronPortCache.getAllPorts()).thenReturn(list_neutronPort);
163         when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
164
165         when(neutronSubnetCache.getSubnet(anyString())).thenReturn(neutronSubnet);
166
167         when(neutronSubnet.getNetworkUUID()).thenReturn("networkUUID");
168
169         when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
170
171         when(neutronNetwork.getRouterExternal()).thenReturn(false); // default true
172         when(neutronNetwork.getProviderSegmentationID()).thenReturn("providerSegmentationId1","providerSegmentationId2", "providerSegmentationId3");
173         when(neutronNetwork.getTenantID()).thenReturn("tenantId");
174         when(neutronNetwork.getNetworkUUID()).thenReturn("networkUUID");
175
176         when(neutronSubnet.getGatewayIP()).thenReturn("gatewayIp");
177         when(neutronSubnet.getCidr()).thenReturn(HOST_ADDRESS + "/32");
178         when(neutronSubnet.getSubnetUUID()).thenReturn("subnetUUID");
179
180         when(tenantNetworkManager.isTenantNetworkPresentInNode(any(Node.class), anyString())).thenReturn(false);
181         when(tenantNetworkManager.isTenantNetworkPresentInNode(any(Node.class), anyString())).thenReturn(true);
182
183         when(node.getNodeId()).thenReturn(nodeID);
184
185         when(nodeID.getValue()).thenReturn("nodeId");
186
187         when(status.isSuccess()).thenReturn(true);
188
189         /* TODO SB_MIGRATION */
190         //when(connectionService.getBridgeNodes()).thenReturn(list_nodes);
191
192         when(configurationService.getDefaultGatewayMacAddress(any(Node.class))).thenReturn("defaultGatewayMacAddress");
193         when(configurationService.getIntegrationBridgeName()).thenReturn("brName");
194
195         //when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(rowMap);
196         //when(ovsdbConfigurationService.getTypedRow(any(Node.class), same(Bridge.class), any(Row.class))).thenReturn(bridge);
197         //when(ovsdbConfigurationService.getRow(any(Node.class), anyString(), anyString())).thenReturn(row);
198
199         //when(bridge.getName()).thenReturn("brName");
200         //when(bridge.getDatapathIdColumn()).thenReturn(bridgeColumnIds);
201
202         //when(bridgeColumnIds.getData()).thenReturn(dpids);
203
204         when(nodeCacheManager.getBridgeNodes()).thenReturn(list_nodes);
205     }
206
207
208     /**
209      * Test method {@link NeutronL3Adapter#handleNeutronPortEvent(NeutronPort, Action)}
210      * Device owner = network:router_interface
211      */
212 //    @Test
213     public void testHandleNeutronPortEvent1() {
214         when(neutronPort.getDeviceOwner()).thenReturn("network:router_interface");
215
216         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
217         // Affected by the add
218         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
219         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
220         /* TODO SB_MIGRATION */
221         //assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
222 //        assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
223 //        assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
224 //        assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
225 //        assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
226         // Unchanged
227         assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
228         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
229         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
230
231         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
232         // Affected by the delete
233         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 0, networkIdToRouterMacCache.size());
234         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
235 //        assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
236         // Unchanged
237         assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
238         assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
239         assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
240         assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
241         assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
242         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
243         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
244     }
245
246     /**
247      * Test method {@link NeutronL3Adapter#handleNeutronPortEvent(NeutronPort, Action)}
248      * Device owner = ""
249      */
250 //    @Test
251     public void testHandleNeutronPortEvent2() {
252         when(neutronPort.getDeviceOwner()).thenReturn("");
253
254         // populate subnetIdToRouterInterfaceCache to pass the
255         // if (neutronRouterInterface != null)
256         NeutronRouter_Interface neutronRouterInterface = mock(NeutronRouter_Interface.class);
257         when(neutronRouterInterface.getPortUUID()).thenReturn("portUUID");
258         when(neutronRouterInterface.getSubnetUUID()).thenReturn("subnetUUID");
259         subnetIdToRouterInterfaceCache.put("subnetUUID", neutronRouterInterface);
260
261         /* device owner = "" */
262         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
263         // Affected by the add
264         /* TODO SB_MIGRATION */
265         //assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
266         assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
267         assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
268         assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
269         assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
270         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
271         // Added above
272         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
273         // Unchanged
274         assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
275         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
276         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
277
278         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
279         // Affected by the delete
280         assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
281         assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
282         // Unchanged
283         assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
284         assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
285         assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
286         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
287         assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
288         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
289         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
290         // Added above
291         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
292     }
293
294     /**
295      * Test method {@link NeutronL3Adapter#handleNeutronFloatingIPEvent(NeutronFloatingIP, Action)}
296      */
297 //    @Test
298     public void testandleNeutronFloatingIPEvent() throws Exception{
299         NeutronFloatingIP neutronFloatingIP = mock(NeutronFloatingIP.class);
300         when(neutronFloatingIP.getFixedIPAddress()).thenReturn(HOST_ADDRESS);
301         when(neutronFloatingIP.getFloatingIPAddress()).thenReturn(HOST_ADDRESS);
302         when(neutronFloatingIP.getFloatingNetworkUUID()).thenReturn("floatingNetworkUUID");
303
304         networkIdToRouterMacCache.put("floatingNetworkUUID", "routerMacAddress");
305
306         neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.ADD);
307         // Added above
308         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
309         // Affected by the add
310         /* TODO SB_MIGRATION */
311         //assertEquals("Error, did not return the correct inboundIpRewriteCache size", 1, inboundIpRewriteCache.size());
312         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 1, outboundIpRewriteCache.size());
313         assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
314         // Unchanged
315         assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
316         assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
317         assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
318         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
319         assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
320         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
321
322         neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.DELETE);
323         // Unchanged
324         assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
325         assertEquals("Error, did not return the correct inboundIpRewriteCache size", 1, inboundIpRewriteCache.size());
326         assertEquals("Error, did not return the correct outboundIpRewriteCache size", 1, outboundIpRewriteCache.size());
327         assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
328         assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
329         assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
330         assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
331         assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
332         assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
333         assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
334     }
335
336     @Test
337     public void testSetDependencies() throws Exception {
338         TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
339         ConfigurationService configurationService = mock(ConfigurationService.class);
340         ArpProvider arpProvider = mock(ArpProvider.class);
341         InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
342         OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
343         RoutingProvider routingProvider = mock(RoutingProvider.class);
344         L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
345         NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
346         Southbound southbound = mock(Southbound.class);
347
348         PowerMockito.mockStatic(ServiceHelper.class);
349         PowerMockito.when(ServiceHelper.getGlobalInstance(TenantNetworkManager.class, neutronL3Adapter)).thenReturn(tenantNetworkManager);
350         PowerMockito.when(ServiceHelper.getGlobalInstance(ConfigurationService.class, neutronL3Adapter)).thenReturn(configurationService);
351         PowerMockito.when(ServiceHelper.getGlobalInstance(ArpProvider.class, neutronL3Adapter)).thenReturn(arpProvider);
352         PowerMockito.when(ServiceHelper.getGlobalInstance(InboundNatProvider.class, neutronL3Adapter)).thenReturn(inboundNatProvider);
353         PowerMockito.when(ServiceHelper.getGlobalInstance(OutboundNatProvider.class, neutronL3Adapter)).thenReturn(outboundNatProvider);
354         PowerMockito.when(ServiceHelper.getGlobalInstance(RoutingProvider.class, neutronL3Adapter)).thenReturn(routingProvider);
355         PowerMockito.when(ServiceHelper.getGlobalInstance(L3ForwardingProvider.class, neutronL3Adapter)).thenReturn(l3ForwardingProvider);
356         PowerMockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, neutronL3Adapter)).thenReturn(nodeCacheManager);
357         PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, neutronL3Adapter)).thenReturn(southbound);
358
359         neutronL3Adapter.setDependencies(mock(BundleContext.class), mock(ServiceReference.class));
360
361         assertEquals("Error, did not return the correct object", getField("tenantNetworkManager"), tenantNetworkManager);
362         assertEquals("Error, did not return the correct object", getField("configurationService"), configurationService);
363         assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
364         assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
365         assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
366         assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
367         assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
368         assertEquals("Error, did not return the correct object", getField("nodeCacheManager"), nodeCacheManager);
369         assertEquals("Error, did not return the correct object", getField("southbound"), southbound);
370     }
371
372     @Test
373     public void testSetDependenciesObject() throws Exception{
374         INeutronNetworkCRUD iNeutronNetworkCRUD = mock(INeutronNetworkCRUD.class);
375         neutronL3Adapter.setDependencies(iNeutronNetworkCRUD);
376         assertEquals("Error, did not return the correct object", getField("neutronNetworkCache"), iNeutronNetworkCRUD);
377
378         INeutronPortCRUD iNeutronPortCRUD = mock(INeutronPortCRUD.class);
379         neutronL3Adapter.setDependencies(iNeutronPortCRUD);
380         assertEquals("Error, did not return the correct object", getField("neutronPortCache"), iNeutronPortCRUD);
381
382         INeutronSubnetCRUD iNeutronSubnetCRUD = mock(INeutronSubnetCRUD.class);
383         neutronL3Adapter.setDependencies(iNeutronSubnetCRUD);
384         assertEquals("Error, did not return the correct object", getField("neutronSubnetCache"), iNeutronSubnetCRUD);
385
386         ArpProvider arpProvider = mock(ArpProvider.class);
387         neutronL3Adapter.setDependencies(arpProvider);
388         assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
389
390         InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
391         neutronL3Adapter.setDependencies(inboundNatProvider);
392         assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
393
394         OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
395         neutronL3Adapter.setDependencies(outboundNatProvider);
396         assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
397
398         RoutingProvider routingProvider = mock(RoutingProvider.class);
399         neutronL3Adapter.setDependencies(routingProvider);
400         assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
401
402         L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
403         neutronL3Adapter.setDependencies(l3ForwardingProvider);
404         assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
405     }
406
407     private Object getField(String fieldName) throws Exception {
408         Field field = NeutronL3Adapter.class.getDeclaredField(fieldName);
409         field.setAccessible(true);
410         return field.get(neutronL3Adapter);
411     }
412
413     private Method getMethod(String methodName) throws Exception {
414         Method method = neutronL3Adapter.getClass().getDeclaredMethod(methodName, new Class[] {});
415         method.setAccessible(true);
416         return method;
417     }
418 }