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