782f5dac2065aedcb79047ca0d887a1fb79e1f25
[groupbasedpolicy.git] / neutron-ovsdb / src / test / java / org / opendaylight / groupbasedpolicy / neutron / ovsdb / util / OvsdbHelperTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.groupbasedpolicy.neutron.ovsdb.util;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.never;
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 import com.google.common.base.Optional;
26 import com.google.common.util.concurrent.CheckedFuture;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
31 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
32 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
33 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
34 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
35 import org.opendaylight.groupbasedpolicy.neutron.ovsdb.AbstractTunnelType;
36 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeVxlan;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeRef;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
62 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
63
64 public class OvsdbHelperTest {
65
66     private static final String TUNNEL_PREFIX = "tunnelPrefix";
67     private static final String KEY_1 = "key1";
68     private static final String VALUE_1 = "value1";
69     private static final String KEY_2 = "key2";
70     private static final String VALUE_2 = "value2";
71
72     private DataBroker dataBroker;
73     private InstanceIdentifier<OvsdbTerminationPointAugmentation> tpIid;
74     private OvsdbBridgeAugmentation ovsdbBridgeAugmentation;
75     private OvsdbNodeAugmentation ovsdbNodeAugmentation;
76     private Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional;
77     private Optional<OvsdbTerminationPointAugmentation> ovsdbTerminationPointOptional;
78     private Optional<Node> nodeOptional;
79     private Node node;
80     private AbstractTunnelType abstractTunnelType;
81     private ReadOnlyTransaction readTransaction;
82     private ReadWriteTransaction readWriteTransaction;
83     private CheckedFuture<Optional<OvsdbBridgeAugmentation>, ReadFailedException> ovsdbBridgeFuture;
84     private CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture;
85     private CheckedFuture<Optional<OvsdbTerminationPointAugmentation>, ReadFailedException> ovsdbTerminationPointFuture;
86
87     @SuppressWarnings({"unchecked", "rawtypes"})
88     @Before
89     public void init() throws Exception {
90         dataBroker = mock(DataBroker.class);
91         tpIid = InstanceIdentifier.create(NetworkTopology.class)
92             .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
93             .child(Node.class)
94             .child(TerminationPoint.class)
95             .augmentation(OvsdbTerminationPointAugmentation.class);
96
97         readTransaction = mock(ReadOnlyTransaction.class);
98         when(dataBroker.newReadOnlyTransaction()).thenReturn(readTransaction);
99         readWriteTransaction = mock(ReadWriteTransaction.class);
100         when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
101         CheckedFuture<Void, TransactionCommitFailedException> submitFuture = mock(CheckedFuture.class);
102         when(readWriteTransaction.submit()).thenReturn(submitFuture);
103
104         ovsdbBridgeFuture = mock(CheckedFuture.class);
105         ovsdbBridgeOptional = mock(Optional.class);
106         when(ovsdbBridgeFuture.checkedGet()).thenReturn(ovsdbBridgeOptional);
107         when(ovsdbBridgeOptional.isPresent()).thenReturn(true);
108         ovsdbBridgeAugmentation = mock(OvsdbBridgeAugmentation.class);
109         when(ovsdbBridgeOptional.get()).thenReturn(ovsdbBridgeAugmentation);
110         OvsdbBridgeName bridgeName = mock(OvsdbBridgeName.class);
111         when(ovsdbBridgeAugmentation.getBridgeName()).thenReturn(bridgeName);
112
113         OvsdbNodeRef bareIid = mock(OvsdbNodeRef.class);
114         when(ovsdbBridgeAugmentation.getManagedBy()).thenReturn(bareIid);
115         when(bareIid.getValue()).thenReturn((InstanceIdentifier) InstanceIdentifier.create(Node.class));
116
117         nodeFuture = mock(CheckedFuture.class);
118         nodeOptional = mock(Optional.class);
119         when(nodeFuture.checkedGet()).thenReturn(nodeOptional);
120         when(nodeOptional.isPresent()).thenReturn(true);
121         node = mock(Node.class);
122         when(nodeOptional.get()).thenReturn(node);
123         when(node.getAugmentation(OvsdbBridgeAugmentation.class)).thenReturn(ovsdbBridgeAugmentation);
124
125         ovsdbTerminationPointFuture = mock(CheckedFuture.class);
126         ovsdbTerminationPointOptional = mock(Optional.class);
127         when(ovsdbTerminationPointFuture.checkedGet()).thenReturn(ovsdbTerminationPointOptional);
128         when(ovsdbTerminationPointOptional.isPresent()).thenReturn(true);
129         OvsdbTerminationPointAugmentation ovsdbTp = mock(OvsdbTerminationPointAugmentation.class);
130         when(ovsdbTerminationPointOptional.get()).thenReturn(ovsdbTp);
131
132         abstractTunnelType = mock(AbstractTunnelType.class);
133         when(abstractTunnelType.getTunnelPrefix()).thenReturn(TUNNEL_PREFIX);
134
135         ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
136         when(node.getAugmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsdbNodeAugmentation);
137     }
138
139     @SuppressWarnings("unchecked")
140     @Test
141     public void testGetOvsdbBridgeFromTerminationPoint() {
142         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
143             .thenReturn(ovsdbBridgeFuture);
144         assertNotNull(OvsdbHelper.getOvsdbBridgeFromTerminationPoint(tpIid, dataBroker));
145         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
146     }
147
148     @SuppressWarnings("unchecked")
149     @Test
150     public void testGetOvsdbBridgeFromTerminationPoint_PresentFalse() {
151         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
152             .thenReturn(ovsdbBridgeFuture);
153         when(ovsdbBridgeOptional.isPresent()).thenReturn(false);
154         assertNull(OvsdbHelper.getOvsdbBridgeFromTerminationPoint(tpIid, dataBroker));
155         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
156     }
157
158     @SuppressWarnings("unchecked")
159     @Test
160     public void testGetOvsdbBridgeFromTerminationPoint_InvalidIid() {
161         InstanceIdentifier<OvsdbTerminationPointAugmentation> invalidIid =
162                 InstanceIdentifier.create(OvsdbTerminationPointAugmentation.class);
163         assertNull(OvsdbHelper.getOvsdbBridgeFromTerminationPoint(invalidIid, dataBroker));
164         verify(readTransaction, never()).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
165     }
166
167     @SuppressWarnings({"unchecked", "rawtypes"})
168     @Test
169     public void testGetNodeFromBridgeRef() {
170         OvsdbBridgeRef bridgeRef = mock(OvsdbBridgeRef.class);
171         when(bridgeRef.getValue()).thenReturn((InstanceIdentifier) tpIid);
172         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
173             .thenReturn(nodeFuture);
174         assertNotNull(OvsdbHelper.getNodeFromBridgeRef(bridgeRef, dataBroker));
175         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
176     }
177
178     @SuppressWarnings({"unchecked", "rawtypes"})
179     @Test
180     public void testGetNodeFromBridgeRef_PresentFalse() {
181         OvsdbBridgeRef bridgeRef = mock(OvsdbBridgeRef.class);
182         when(bridgeRef.getValue()).thenReturn((InstanceIdentifier) tpIid);
183         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
184             .thenReturn(nodeFuture);
185         when(nodeOptional.isPresent()).thenReturn(false);
186         assertNull(OvsdbHelper.getNodeFromBridgeRef(bridgeRef, dataBroker));
187         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
188     }
189
190     @SuppressWarnings("unchecked")
191     @Test
192     public void testGetOvsdbTerminationPoint() {
193         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
194             .thenReturn(ovsdbTerminationPointFuture);
195         assertNotNull(OvsdbHelper.getOvsdbTerminationPoint(tpIid, dataBroker));
196         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
197     }
198
199     @SuppressWarnings("unchecked")
200     @Test
201     public void testGetOvsdbTerminationPoint_PresentFalse() {
202         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
203             .thenReturn(ovsdbTerminationPointFuture);
204         when(ovsdbTerminationPointOptional.isPresent()).thenReturn(false);
205         assertNull(OvsdbHelper.getOvsdbTerminationPoint(tpIid, dataBroker));
206         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
207     }
208
209     @Test
210     public void testGetNode() {
211         NodeBuilder nodeBuilder = new NodeBuilder();
212         nodeBuilder.setKey(new NodeKey(new NodeId("nodeId")));
213
214         TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
215         tpBuilder.setKey(new TerminationPointKey(new TpId("tpId")));
216
217         OvsdbBridgeAugmentationBuilder augmentationBuilder = new OvsdbBridgeAugmentationBuilder();
218         augmentationBuilder.setBridgeName(new OvsdbBridgeName("bridgeName"));
219
220         Node node = OvsdbHelper.getNode(nodeBuilder.build(), Collections.singletonList(tpBuilder.build()),
221                 augmentationBuilder.build());
222         assertNotNull(node);
223         assertEquals("nodeId", node.getKey().getNodeId().getValue());
224         assertEquals(1, node.getTerminationPoint().size());
225         TerminationPoint terminationPoint = node.getTerminationPoint().get(0);
226         assertNotNull(terminationPoint);
227         assertEquals("tpId", terminationPoint.getKey().getTpId().getValue());
228         assertEquals("bridgeName", node.getAugmentation(OvsdbBridgeAugmentation.class).getBridgeName().getValue());
229     }
230
231     @Test
232     public void testBuildOvsdbBridgeAugmentation() {
233         final InstanceIdentifier<Node> nodeIid = InstanceIdentifier.builder(NetworkTopology.class)
234             .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
235             .child(Node.class)
236             .build();
237
238         OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
239         bridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName("bridgeName"));
240         bridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(nodeIid));
241
242         OvsdbNodeAugmentationBuilder nodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
243
244         ConnectionInfoBuilder ciBuilder = new ConnectionInfoBuilder();
245         ciBuilder.setLocalIp(new IpAddress(new Ipv4Address("127.0.0.1")));
246         nodeAugmentationBuilder.setConnectionInfo(ciBuilder.build());
247
248         OvsdbBridgeAugmentation augmentation = OvsdbHelper
249             .buildOvsdbBridgeAugmentation(bridgeAugmentationBuilder.build(), nodeAugmentationBuilder.build());
250         assertNotNull(augmentation);
251         assertNotNull("bridgeName", augmentation.getBridgeName().getValue());
252         assertEquals(nodeIid, augmentation.getManagedBy().getValue());
253         assertEquals(1, augmentation.getControllerEntry().size());
254         ControllerEntry controllerEntry = augmentation.getControllerEntry().get(0);
255         assertNotNull(controllerEntry);
256         assertFalse(controllerEntry.getTarget().getValue().isEmpty());
257     }
258
259     @Test
260     public void testBuildOvsdbBridgeAugmentation_ManagerIpNull() {
261         final InstanceIdentifier<Node> nodeIid = InstanceIdentifier.builder(NetworkTopology.class)
262             .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
263             .child(Node.class)
264             .build();
265
266         OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
267         bridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName("bridgeName"));
268         bridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(nodeIid));
269
270         OvsdbNodeAugmentationBuilder nodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
271
272         OvsdbBridgeAugmentation augmentation = OvsdbHelper
273             .buildOvsdbBridgeAugmentation(bridgeAugmentationBuilder.build(), nodeAugmentationBuilder.build());
274         assertNotNull(augmentation);
275         assertNotNull("bridgeName", augmentation.getBridgeName().getValue());
276         assertEquals(nodeIid, augmentation.getManagedBy().getValue());
277         assertNull(augmentation.getControllerEntry());
278     }
279
280     @Test
281     public void testBuildTerminationPoints() {
282         OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
283         bridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName("bridgeName"));
284
285         List<Options> options = new ArrayList<>();
286         OvsdbHelper.setOption(options, "optionKey", "optionValue");
287
288         OvsdbTerminationPointAugmentation terminationPointAugmentation = OvsdbHelper
289             .buildOvsdbTerminationPointAugmentation(bridgeAugmentationBuilder.build(), options, abstractTunnelType);
290
291         List<TerminationPoint> terminationPoints = OvsdbHelper.buildTerminationPoints(bridgeAugmentationBuilder.build(),
292                 terminationPointAugmentation, abstractTunnelType);
293         assertNotNull(terminationPoints);
294         assertEquals(1, terminationPoints.size());
295         TerminationPoint terminationPoint = terminationPoints.get(0);
296         assertNotNull(terminationPoint);
297         assertEquals(TUNNEL_PREFIX + "bridgeName", terminationPoint.getTpId().getValue());
298         OvsdbTerminationPointAugmentation tpAugmentation =
299                 terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
300         assertNotNull(tpAugmentation);
301         assertEquals(TUNNEL_PREFIX + "bridgeName", tpAugmentation.getName());
302         assertEquals(1, tpAugmentation.getOptions().size());
303         Options tpOption = tpAugmentation.getOptions().get(0);
304         assertNotNull(tpOption);
305         assertEquals("optionKey", tpOption.getOption());
306         assertEquals("optionValue", tpOption.getValue());
307         assertEquals(TerminationPoint.class, terminationPoint.getImplementedInterface());
308     }
309
310     @Test
311     public void testBuildOvsdbTerminationPointAugmentation() {
312         OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
313         bridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName("bridgeName"));
314         List<Options> expectedOptions = new ArrayList<>();
315         OvsdbHelper.setOption(expectedOptions, "optionKey", "optionValue");
316         OvsdbTerminationPointAugmentation augmentation = OvsdbHelper.buildOvsdbTerminationPointAugmentation(
317                 bridgeAugmentationBuilder.build(), expectedOptions, abstractTunnelType);
318         assertNotNull(augmentation);
319         assertEquals(TUNNEL_PREFIX + "bridgeName", augmentation.getName());
320         assertEquals(1, augmentation.getOptions().size());
321         Options option = augmentation.getOptions().get(0);
322         assertNotNull(option);
323         assertEquals("optionKey", option.getOption());
324         assertEquals("optionValue", option.getValue());
325         assertEquals(InterfaceTypeVxlan.class, augmentation.getInterfaceType());
326     }
327
328     @Test
329     public void testSetOption() {
330         List<Options> options = new ArrayList<>();
331         OvsdbHelper.setOption(options, KEY_1, VALUE_1);
332         assertEquals(1, options.size());
333
334         Options option = options.get(0);
335         assertNotNull(option);
336         assertEquals(KEY_1, option.getOption());
337         assertEquals(KEY_1, option.getKey().getOption());
338         assertEquals(VALUE_1, option.getValue());
339
340         OvsdbHelper.setOption(options, KEY_2, VALUE_2);
341         assertEquals(2, options.size());
342
343         option = options.get(0);
344         assertNotNull(option);
345         assertEquals(KEY_1, option.getOption());
346         assertEquals(KEY_1, option.getKey().getOption());
347         assertEquals(VALUE_1, option.getValue());
348
349         option = options.get(1);
350         assertNotNull(option);
351         assertEquals(KEY_2, option.getOption());
352         assertEquals(KEY_2, option.getKey().getOption());
353         assertEquals(VALUE_2, option.getValue());
354     }
355
356     @Test
357     public void testGetNodeIp() {
358         OvsdbNodeAugmentationBuilder nodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
359         ConnectionInfoBuilder ciBuilder = new ConnectionInfoBuilder();
360         ciBuilder.setRemoteIp(new IpAddress(new Ipv4Address("192.168.50.10")));
361         nodeAugmentationBuilder.setConnectionInfo(ciBuilder.build());
362
363         IpAddress nodeIpAddress = OvsdbHelper.getNodeIp(nodeAugmentationBuilder.build());
364         assertNotNull(nodeIpAddress);
365         assertEquals("192.168.50.10", nodeIpAddress.getIpv4Address().getValue());
366     }
367
368     @Test
369     public void testGetNodeIp_IpNotSet() {
370         OvsdbNodeAugmentationBuilder nodeAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
371         nodeAugmentationBuilder.setConnectionInfo(new ConnectionInfoBuilder().build());
372         assertNull(OvsdbHelper.getNodeIp(nodeAugmentationBuilder.build()));
373     }
374
375     @Test
376     public void testGetNodeIp_ConnectionInfoNull() {
377         assertNull(OvsdbHelper.getNodeIp(new OvsdbNodeAugmentationBuilder().build()));
378     }
379
380     @Test
381     public void testGetManagedNode_ManagedByNotSet() {
382         assertNull(OvsdbHelper.getManagerNode(new OvsdbBridgeAugmentationBuilder().build(), dataBroker));
383     }
384
385     @SuppressWarnings("unchecked")
386     @Test
387     public void getManagedNode_InvalidTargetTypeForManagedBy() {
388         final InstanceIdentifier<NetworkTopology> nodeIid = InstanceIdentifier.builder(NetworkTopology.class).build();
389         OvsdbBridgeAugmentationBuilder bridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
390         bridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(nodeIid));
391         assertNull(OvsdbHelper.getManagerNode(bridgeAugmentationBuilder.build(), dataBroker));
392         verify(readTransaction, never()).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
393     }
394
395     @SuppressWarnings("unchecked")
396     @Test
397     public void testGetTopologyNode() {
398         InstanceIdentifier<Node> nodeIid = InstanceIdentifier.create(Node.class);
399         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
400             .thenReturn(nodeFuture);
401         assertEquals(node, OvsdbHelper.getTopologyNode(nodeIid, dataBroker));
402         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
403     }
404
405     @SuppressWarnings("unchecked")
406     @Test
407     public void testGetTopologyNode_PresentFalse() {
408         InstanceIdentifier<Node> nodeIid = InstanceIdentifier.create(Node.class);
409         when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
410             .thenReturn(nodeFuture);
411         when(nodeOptional.isPresent()).thenReturn(false);
412         assertNull(OvsdbHelper.getTopologyNode(nodeIid, dataBroker));
413         verify(readTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
414     }
415
416     @SuppressWarnings("unchecked")
417     @Test
418     public void testCreateTunnelPort() {
419         InstanceIdentifier<Node> nodeIid = InstanceIdentifier.create(Node.class);
420         when(readWriteTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
421             .thenReturn(nodeFuture);
422         OvsdbHelper.createTunnelPort(nodeIid, node, abstractTunnelType, dataBroker);
423         verify(readWriteTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
424         verify(readWriteTransaction).submit();
425     }
426
427     @Test
428     public void testCreateTunnelPort_BridgeNull() {
429         InstanceIdentifier<Node> nodeIid = InstanceIdentifier.create(Node.class);
430         when(node.getAugmentation(OvsdbBridgeAugmentation.class)).thenReturn(null);
431         OvsdbHelper.createTunnelPort(nodeIid, node, abstractTunnelType, dataBroker);
432         verify(readWriteTransaction, never()).submit();
433     }
434
435     @SuppressWarnings("unchecked")
436     @Test
437     public void testCreateTunnelPort_ManagerNodeNull() {
438         InstanceIdentifier<Node> nodeIid = InstanceIdentifier.create(Node.class);
439         when(readWriteTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
440             .thenReturn(nodeFuture);
441         when(nodeOptional.isPresent()).thenReturn(false);
442         OvsdbHelper.createTunnelPort(nodeIid, node, abstractTunnelType, dataBroker);
443         verify(readWriteTransaction).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
444         verify(readWriteTransaction, never()).submit();
445     }
446 }