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
9 package org.opendaylight.ovsdb.openstack.netvirt.impl;
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;
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;
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;
62 * Unit test for {@link NeutronL3Adapter}
64 @PrepareForTest({ConfigProperties.class, ServiceHelper.class})
65 @RunWith(PowerMockRunner.class)
66 public class NeutronL3AdapterTest {
68 @InjectMocks private NeutronL3Adapter neutronL3Adapter;
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;
78 @Mock private NeutronPort neutronPort;
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;
91 private static final String HOST_ADDRESS = "127.0.0.1";
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 PowerMockito.when(ConfigProperties.getProperty(neutronL3Adapter.getClass(), "ovsdb.l3.arp.responder.disabled")).thenReturn("no");
99 when(configurationService.isL3ForwardingEnabled()).thenReturn(true);
101 this.getMethod("initL3AdapterMembers").invoke(neutronL3Adapter);
103 this.getNeutronL3AdapterFields();
112 private void getNeutronL3AdapterFields() throws Exception{
113 inboundIpRewriteCache = (Set<String>) getField("inboundIpRewriteCache");
114 outboundIpRewriteCache = (Set<String>) getField("outboundIpRewriteCache");
115 inboundIpRewriteExclusionCache = (Set<String>) getField("inboundIpRewriteExclusionCache");
116 outboundIpRewriteExclusionCache = (Set<String>) getField("outboundIpRewriteExclusionCache");
117 routerInterfacesCache = (Set<String>) getField("routerInterfacesCache");
118 staticArpEntryCache = (Set<String>) getField("staticArpEntryCache");
119 l3ForwardingCache = (Set<String>) getField("l3ForwardingCache");
120 defaultRouteCache = (Set<String>) getField("defaultRouteCache");
121 networkIdToRouterMacCache = (Map<String, String>) getField("networkIdToRouterMacCache");
122 subnetIdToRouterInterfaceCache = (Map<String, NeutronRouter_Interface>) getField("subnetIdToRouterInterfaceCache");
125 private void setUpVar(){
126 Neutron_IPs neutronIP = mock(Neutron_IPs.class);
127 NeutronRouter neutronRouter = mock(NeutronRouter.class);
129 NeutronSubnet neutronSubnet = mock(NeutronSubnet.class);
130 NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
131 Node node = mock(Node.class);
132 NodeId nodeID = mock(NodeId.class);
134 //Row row = mock(Row.class);
135 //Bridge bridge = mock(Bridge.class);
136 Status status = mock(Status.class);
138 List<Neutron_IPs> list_neutronIP = new ArrayList<Neutron_IPs>();
139 list_neutronIP.add(neutronIP);
141 List<NeutronPort> list_neutronPort = new ArrayList<>();
142 list_neutronPort.add(neutronPort);
144 List<Node> list_nodes = new ArrayList<Node>();
145 list_nodes.add(node);
147 //ConcurrentMap<String, Row> rowMap = mock(ConcurrentMap.class);
148 //rowMap.put("key", row);
150 //Column<GenericTableSchema, Set<String>> bridgeColumnIds = mock(Column.class);
151 Set<String> dpids = new HashSet();
154 when(neutronPort.getFixedIPs()).thenReturn(list_neutronIP);
155 when(neutronPort.getPortUUID()).thenReturn("portUUID");
156 when(neutronPort.getTenantID()).thenReturn("tenantID");
157 when(neutronPort.getNetworkUUID()).thenReturn("networkUUID");
158 when(neutronPort.getMacAddress()).thenReturn("macAddress1").thenReturn("macAddress2");
160 when(neutronIP.getSubnetUUID()).thenReturn("subnetUUID");
161 when(neutronIP.getIpAddress()).thenReturn(HOST_ADDRESS);
163 when(neutronPortCache.getAllPorts()).thenReturn(list_neutronPort);
164 when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
166 when(neutronSubnetCache.getSubnet(anyString())).thenReturn(neutronSubnet);
168 when(neutronSubnet.getNetworkUUID()).thenReturn("networkUUID");
170 when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
172 when(neutronNetwork.getRouterExternal()).thenReturn(false); // default true
173 when(neutronNetwork.getProviderSegmentationID()).thenReturn("providerSegmentationId1","providerSegmentationId2", "providerSegmentationId3");
174 when(neutronNetwork.getTenantID()).thenReturn("tenantId");
175 when(neutronNetwork.getNetworkUUID()).thenReturn("networkUUID");
177 when(neutronSubnet.getGatewayIP()).thenReturn("gatewayIp");
178 when(neutronSubnet.getCidr()).thenReturn(HOST_ADDRESS + "/32");
179 when(neutronSubnet.getSubnetUUID()).thenReturn("subnetUUID");
181 when(tenantNetworkManager.isTenantNetworkPresentInNode(any(Node.class), anyString())).thenReturn(false);
182 when(tenantNetworkManager.isTenantNetworkPresentInNode(any(Node.class), anyString())).thenReturn(true);
184 when(node.getNodeId()).thenReturn(nodeID);
186 when(nodeID.getValue()).thenReturn("nodeId");
188 when(status.isSuccess()).thenReturn(true);
190 /* TODO SB_MIGRATION */
191 //when(connectionService.getBridgeNodes()).thenReturn(list_nodes);
193 when(configurationService.getDefaultGatewayMacAddress(any(Node.class))).thenReturn("defaultGatewayMacAddress");
194 when(configurationService.getIntegrationBridgeName()).thenReturn("brName");
196 //when(ovsdbConfigurationService.getRows(any(Node.class), anyString())).thenReturn(rowMap);
197 //when(ovsdbConfigurationService.getTypedRow(any(Node.class), same(Bridge.class), any(Row.class))).thenReturn(bridge);
198 //when(ovsdbConfigurationService.getRow(any(Node.class), anyString(), anyString())).thenReturn(row);
200 //when(bridge.getName()).thenReturn("brName");
201 //when(bridge.getDatapathIdColumn()).thenReturn(bridgeColumnIds);
203 //when(bridgeColumnIds.getData()).thenReturn(dpids);
205 when(nodeCacheManager.getBridgeNodes()).thenReturn(list_nodes);
210 * Test method {@link NeutronL3Adapter#handleNeutronPortEvent(NeutronPort, Action)}
211 * Device owner = network:router_interface
214 public void testHandleNeutronPortEvent1() {
215 when(neutronPort.getDeviceOwner()).thenReturn("network:router_interface");
217 neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
218 // Affected by the add
219 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
220 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
221 /* TODO SB_MIGRATION */
222 //assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
223 // assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
224 // assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
225 // assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
226 // assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
228 assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
229 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
230 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
232 neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
233 // Affected by the delete
234 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 0, networkIdToRouterMacCache.size());
235 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
236 // assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
238 assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
239 assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
240 assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
241 assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
242 assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
243 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
244 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
248 * Test method {@link NeutronL3Adapter#handleNeutronPortEvent(NeutronPort, Action)}
252 public void testHandleNeutronPortEvent2() {
253 when(neutronPort.getDeviceOwner()).thenReturn("");
255 // populate subnetIdToRouterInterfaceCache to pass the
256 // if (neutronRouterInterface != null)
257 NeutronRouter_Interface neutronRouterInterface = mock(NeutronRouter_Interface.class);
258 when(neutronRouterInterface.getPortUUID()).thenReturn("portUUID");
259 when(neutronRouterInterface.getSubnetUUID()).thenReturn("subnetUUID");
260 subnetIdToRouterInterfaceCache.put("subnetUUID", neutronRouterInterface);
262 /* device owner = "" */
263 neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
264 // Affected by the add
265 /* TODO SB_MIGRATION */
266 //assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
267 assertEquals("Error, did not return the correct staticArpEntryCache size", 2, staticArpEntryCache.size());
268 assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
269 assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
270 assertEquals("Error, did not return the correct l3ForwardingCache size", 1, l3ForwardingCache.size());
271 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
273 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
275 assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
276 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
277 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
279 neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
280 // Affected by the delete
281 assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
282 assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
284 assertEquals("Error, did not return the correct routerInterfacesCache size", 2, routerInterfacesCache.size());
285 assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 1, inboundIpRewriteExclusionCache.size());
286 assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 1, outboundIpRewriteExclusionCache.size());
287 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
288 assertEquals("Error, did not return the correct inboundIpRewriteCache size", 0, inboundIpRewriteCache.size());
289 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 0, outboundIpRewriteCache.size());
290 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
292 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 1, subnetIdToRouterInterfaceCache.size());
296 * Test method {@link NeutronL3Adapter#handleNeutronFloatingIPEvent(NeutronFloatingIP, Action)}
299 public void testandleNeutronFloatingIPEvent() throws Exception{
300 NeutronFloatingIP neutronFloatingIP = mock(NeutronFloatingIP.class);
301 when(neutronFloatingIP.getFixedIPAddress()).thenReturn(HOST_ADDRESS);
302 when(neutronFloatingIP.getFloatingIPAddress()).thenReturn(HOST_ADDRESS);
303 when(neutronFloatingIP.getFloatingNetworkUUID()).thenReturn("floatingNetworkUUID");
305 networkIdToRouterMacCache.put("floatingNetworkUUID", "routerMacAddress");
307 neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.ADD);
309 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
310 // Affected by the add
311 /* TODO SB_MIGRATION */
312 //assertEquals("Error, did not return the correct inboundIpRewriteCache size", 1, inboundIpRewriteCache.size());
313 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 1, outboundIpRewriteCache.size());
314 assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
316 assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
317 assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
318 assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
319 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
320 assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
321 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
323 neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.DELETE);
325 assertEquals("Error, did not return the correct networkIdToRouterMacCache size", 1, networkIdToRouterMacCache.size());
326 assertEquals("Error, did not return the correct inboundIpRewriteCache size", 1, inboundIpRewriteCache.size());
327 assertEquals("Error, did not return the correct outboundIpRewriteCache size", 1, outboundIpRewriteCache.size());
328 assertEquals("Error, did not return the correct staticArpEntryCache size", 1, staticArpEntryCache.size());
329 assertEquals("Error, did not return the correct routerInterfacesCache size", 0, routerInterfacesCache.size());
330 assertEquals("Error, did not return the correct inboundIpRewriteExclusionCache size", 0, inboundIpRewriteExclusionCache.size());
331 assertEquals("Error, did not return the correct outboundIpRewriteExclusionCache size", 0, outboundIpRewriteExclusionCache.size());
332 assertEquals("Error, did not return the correct subnetIdToRouterInterfaceCache size", 0, subnetIdToRouterInterfaceCache.size());
333 assertEquals("Error, did not return the correct l3ForwardingCache size", 0, l3ForwardingCache.size());
334 assertEquals("Error, did not return the correct defaultRouteCache size", 0, defaultRouteCache.size());
338 public void testSetDependencies() throws Exception {
339 TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
340 ConfigurationService configurationService = mock(ConfigurationService.class);
341 ArpProvider arpProvider = mock(ArpProvider.class);
342 InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
343 OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
344 RoutingProvider routingProvider = mock(RoutingProvider.class);
345 L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
346 NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
347 Southbound southbound = mock(Southbound.class);
349 PowerMockito.mockStatic(ServiceHelper.class);
350 PowerMockito.when(ServiceHelper.getGlobalInstance(TenantNetworkManager.class, neutronL3Adapter)).thenReturn(tenantNetworkManager);
351 PowerMockito.when(ServiceHelper.getGlobalInstance(ConfigurationService.class, neutronL3Adapter)).thenReturn(configurationService);
352 PowerMockito.when(ServiceHelper.getGlobalInstance(ArpProvider.class, neutronL3Adapter)).thenReturn(arpProvider);
353 PowerMockito.when(ServiceHelper.getGlobalInstance(InboundNatProvider.class, neutronL3Adapter)).thenReturn(inboundNatProvider);
354 PowerMockito.when(ServiceHelper.getGlobalInstance(OutboundNatProvider.class, neutronL3Adapter)).thenReturn(outboundNatProvider);
355 PowerMockito.when(ServiceHelper.getGlobalInstance(RoutingProvider.class, neutronL3Adapter)).thenReturn(routingProvider);
356 PowerMockito.when(ServiceHelper.getGlobalInstance(L3ForwardingProvider.class, neutronL3Adapter)).thenReturn(l3ForwardingProvider);
357 PowerMockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, neutronL3Adapter)).thenReturn(nodeCacheManager);
358 PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, neutronL3Adapter)).thenReturn(southbound);
360 neutronL3Adapter.setDependencies(mock(BundleContext.class), mock(ServiceReference.class));
362 assertEquals("Error, did not return the correct object", getField("tenantNetworkManager"), tenantNetworkManager);
363 assertEquals("Error, did not return the correct object", getField("configurationService"), configurationService);
364 assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
365 assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
366 assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
367 assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
368 assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
369 assertEquals("Error, did not return the correct object", getField("nodeCacheManager"), nodeCacheManager);
370 assertEquals("Error, did not return the correct object", getField("southbound"), southbound);
374 public void testSetDependenciesObject() throws Exception{
375 INeutronNetworkCRUD iNeutronNetworkCRUD = mock(INeutronNetworkCRUD.class);
376 neutronL3Adapter.setDependencies(iNeutronNetworkCRUD);
377 assertEquals("Error, did not return the correct object", getField("neutronNetworkCache"), iNeutronNetworkCRUD);
379 INeutronPortCRUD iNeutronPortCRUD = mock(INeutronPortCRUD.class);
380 neutronL3Adapter.setDependencies(iNeutronPortCRUD);
381 assertEquals("Error, did not return the correct object", getField("neutronPortCache"), iNeutronPortCRUD);
383 INeutronSubnetCRUD iNeutronSubnetCRUD = mock(INeutronSubnetCRUD.class);
384 neutronL3Adapter.setDependencies(iNeutronSubnetCRUD);
385 assertEquals("Error, did not return the correct object", getField("neutronSubnetCache"), iNeutronSubnetCRUD);
387 ArpProvider arpProvider = mock(ArpProvider.class);
388 neutronL3Adapter.setDependencies(arpProvider);
389 assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
391 InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
392 neutronL3Adapter.setDependencies(inboundNatProvider);
393 assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
395 OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
396 neutronL3Adapter.setDependencies(outboundNatProvider);
397 assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
399 RoutingProvider routingProvider = mock(RoutingProvider.class);
400 neutronL3Adapter.setDependencies(routingProvider);
401 assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
403 L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
404 neutronL3Adapter.setDependencies(l3ForwardingProvider);
405 assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
408 private Object getField(String fieldName) throws Exception {
409 Field field = NeutronL3Adapter.class.getDeclaredField(fieldName);
410 field.setAccessible(true);
411 return field.get(neutronL3Adapter);
414 private Method getMethod(String methodName) throws Exception {
415 Method method = neutronL3Adapter.getClass().getDeclaredMethod(methodName, new Class[] {});
416 method.setAccessible(true);