Switch to MD-SAL APIs
[openflowplugin.git] / applications / topology-manager / src / test / java / org / opendaylight / openflowplugin / applications / topology / manager / NodeChangeListenerImplTest.java
index 676844a6bb4228de7d43ebb4189f09f6ae4f7133..526012ddde339fae406bb6163a383113845b5304 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -9,12 +9,12 @@ package org.opendaylight.openflowplugin.applications.topology.manager;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.WRITE;
+import static org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType.DELETE;
+import static org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType.WRITE;
 import static org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.assertDeletedIDs;
 import static org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newDestNode;
 import static org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newInvNodeKey;
@@ -27,19 +27,17 @@ import static org.opendaylight.openflowplugin.applications.topology.manager.Test
 import static org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.waitForDeletes;
 import static org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.waitForSubmit;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.topology.inventory.rev131030.InventoryNode;
@@ -50,20 +48,20 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-public class NodeChangeListenerImplTest extends DataChangeListenerBase {
+public class NodeChangeListenerImplTest extends DataTreeChangeListenerBase {
     @SuppressWarnings({ "rawtypes" })
     @Test
     public void testOnNodeRemoved() {
-
         NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
-        InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
-        Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
+        final InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
+        Node topoNode = new NodeBuilder().withKey(topoNodeKey).build();
 
-        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
-                                                                nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
-        InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(
+        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819
+                .nodes.NodeKey nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
+        final InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
                 nodeKey);
 
@@ -73,24 +71,22 @@ public class NodeChangeListenerImplTest extends DataChangeListenerBase {
                 newLink("link2", newSourceNode("source2"), newDestNode("dest2")));
         final Topology topology = new TopologyBuilder().setLink(linkList).build();
 
-        InstanceIdentifier[] expDeletedIIDs = {
-                topologyIID.child(Link.class, linkList.get(0).getKey()),
-                topologyIID.child(Link.class, linkList.get(1).getKey()),
+        final InstanceIdentifier[] expDeletedIIDs = {
+                topologyIID.child(Link.class, linkList.get(0).key()),
+                topologyIID.child(Link.class, linkList.get(1).key()),
                 topologyIID.child(Node.class, new NodeKey(new NodeId("node1")))
             };
 
         SettableFuture<Optional<Topology>> readFuture = SettableFuture.create();
         readFuture.set(Optional.of(topology));
         ReadWriteTransaction mockTx1 = mock(ReadWriteTransaction.class);
-        doReturn(Futures.makeChecked(readFuture, ReadFailedException.MAPPER)).when(mockTx1)
-                .read(LogicalDatastoreType.OPERATIONAL, topologyIID);
+        doReturn(readFuture).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
 
         SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
         readFutureNode.set(Optional.of(topoNode));
-        doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx1)
-                .read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
+        doReturn(readFutureNode).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
 
-        CountDownLatch submitLatch1 = setupStubbedSubmit(mockTx1);
+        final CountDownLatch submitLatch1 = setupStubbedSubmit(mockTx1);
 
         int expDeleteCalls = expDeletedIIDs.length;
         CountDownLatch deleteLatch = new CountDownLatch(expDeleteCalls);
@@ -120,27 +116,25 @@ public class NodeChangeListenerImplTest extends DataChangeListenerBase {
 
         NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
         InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
-        Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
+        Node topoNode = new NodeBuilder().withKey(topoNodeKey).build();
 
         org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
                 nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
-        InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(
+        final InstanceIdentifier<?> invNodeID = InstanceIdentifier.create(Nodes.class).child(
                 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
                 nodeKey);
 
-        InstanceIdentifier[] expDeletedIIDs = {
+        final InstanceIdentifier[] expDeletedIIDs = {
                 topologyIID.child(Node.class, new NodeKey(new NodeId("node1")))
             };
 
         ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
-        doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(mockTx)
+        doReturn(FluentFutures.immediateFluentFuture(Optional.empty())).when(mockTx)
                 .read(LogicalDatastoreType.OPERATIONAL, topologyIID);
-        CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
+        final CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
 
-        SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
-        readFutureNode.set(Optional.of(topoNode));
-        doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx)
-                .read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
+        doReturn(FluentFutures.immediateFluentFuture(Optional.of(topoNode))).when(mockTx)
+            .read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
 
         CountDownLatch deleteLatch = new CountDownLatch(1);
         ArgumentCaptor<InstanceIdentifier> deletedLinkIDs =
@@ -182,7 +176,7 @@ public class NodeChangeListenerImplTest extends DataChangeListenerBase {
         verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(topologyIID.child(Node.class,
                 new NodeKey(expNodeId))), mergedNode.capture(), eq(true));
         assertEquals("getNodeId", expNodeId, mergedNode.getValue().getNodeId());
-        InventoryNode augmentation = mergedNode.getValue().getAugmentation(InventoryNode.class);
+        InventoryNode augmentation = mergedNode.getValue().augmentation(InventoryNode.class);
         assertNotNull("Missing augmentation", augmentation);
         assertEquals("getInventoryNodeRef", new NodeRef(invNodeID), augmentation.getInventoryNodeRef());
     }