Teach NETCONF about YANG 1.1 actions in cluster topology
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / NetconfTopologyManagerTest.java
index 01a7749a123e69677f22afea57f370e68dea70a6..737ec7c96381269f47dc758b84f0a9488a2710dc 100644 (file)
@@ -5,12 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.topology.singleton.impl;
 
 import static org.awaitility.Awaitility.await;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
@@ -21,21 +20,22 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.MockitoAnnotations.initMocks;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.SUBTREE_MODIFIED;
-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.SUBTREE_MODIFIED;
+import static org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType.WRITE;
 
 import akka.util.Timeout;
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
 import io.netty.util.concurrent.EventExecutor;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
-import javax.annotation.Nonnull;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -44,19 +44,22 @@ import org.opendaylight.aaa.encrypt.AAAEncryptionService;
 import org.opendaylight.controller.cluster.ActorSystemProvider;
 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
 import org.opendaylight.controller.config.threadpool.ThreadPool;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.test.ConstantSchemaAbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
@@ -76,7 +79,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
 public class NetconfTopologyManagerTest {
     private static final int ACTOR_RESPONSE_WAIT_TIME = 10;
@@ -99,9 +101,9 @@ public class NetconfTopologyManagerTest {
     public void setUp() throws Exception {
         initMocks(this);
 
-        ConstantSchemaAbstractDataBrokerTest dataBrokerTest = new ConstantSchemaAbstractDataBrokerTest(false) {
+        AbstractDataBrokerTest dataBrokerTest = new AbstractDataBrokerTest() {
             @Override
-            protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+            protected Set<YangModuleInfo> getModuleInfos() throws Exception {
                 return ImmutableSet.of(BindingReflections.getModuleInfo(NetworkTopology.class),
                         BindingReflections.getModuleInfo(Topology.class));
             }
@@ -110,23 +112,28 @@ public class NetconfTopologyManagerTest {
         dataBrokerTest.setup();
         dataBroker = spy(dataBrokerTest.getDataBroker());
 
-        final RpcProviderRegistry rpcProviderRegistry = mock(RpcProviderRegistry.class);
+        final DOMRpcProviderService rpcProviderRegistry = mock(DOMRpcProviderService.class);
         final ScheduledThreadPool keepaliveExecutor = mock(ScheduledThreadPool.class);
-        final ThreadPool processingExecutor = mock(ThreadPool.class);
+        final ThreadPool processingThreadPool = mock(ThreadPool.class);
+        final ExecutorService processingService = mock(ExecutorService.class);
+        doReturn(processingService).when(processingThreadPool).getExecutor();
         final ActorSystemProvider actorSystemProvider = mock(ActorSystemProvider.class);
         final EventExecutor eventExecutor = mock(EventExecutor.class);
         final NetconfClientDispatcher clientDispatcher = mock(NetconfClientDispatcher.class);
         final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
         final AAAEncryptionService encryptionService = mock(AAAEncryptionService.class);
+        final DeviceActionFactory deviceActionFactory = mock(DeviceActionFactory.class);
+        final DOMActionProviderService actionProviderRegistry = mock(DOMActionProviderService.class);
 
         final Config config = new ConfigBuilder().setWriteTransactionIdleTimeout(0).build();
-        netconfTopologyManager = new NetconfTopologyManager(dataBroker, rpcProviderRegistry,
-                clusterSingletonServiceProvider, keepaliveExecutor, processingExecutor,
+        netconfTopologyManager = new NetconfTopologyManager(dataBroker, rpcProviderRegistry, actionProviderRegistry,
+                clusterSingletonServiceProvider, keepaliveExecutor, processingThreadPool,
                 actorSystemProvider, eventExecutor, clientDispatcher, TOPOLOGY_ID, config,
-                mountPointService, encryptionService) {
+                mountPointService, encryptionService, deviceActionFactory) {
             @Override
-            protected NetconfTopologyContext newNetconfTopologyContext(NetconfTopologySetup setup,
-                    ServiceGroupIdentifier serviceGroupIdent, Timeout actorResponseWaitTime) {
+            protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup,
+                    final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime,
+                    final DeviceActionFactory deviceActionFactory) {
                 assertEquals(ACTOR_RESPONSE_WAIT_TIME, actorResponseWaitTime.duration().toSeconds());
                 return Objects.requireNonNull(mockContextMap.get(setup.getInstanceIdentifier()),
                         "No mock context for " + setup.getInstanceIdentifier()).apply(setup);
@@ -143,7 +150,7 @@ public class NetconfTopologyManagerTest {
         netconfTopologyManager.init();
 
         await().atMost(5, TimeUnit.SECONDS).until(() -> {
-            ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+            ReadTransaction readTx = dataBroker.newReadOnlyTransaction();
             Optional<Topology> config = readTx.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
             Optional<Topology> oper = readTx.read(LogicalDatastoreType.OPERATIONAL,
@@ -154,7 +161,7 @@ public class NetconfTopologyManagerTest {
         // verify registration is called with right parameters
 
         verify(dataBroker).registerDataTreeChangeListener(
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, NetconfTopologyUtils
+                DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, NetconfTopologyUtils
                         .createTopologyListPath(TOPOLOGY_ID).child(Node.class)), netconfTopologyManager);
 
         netconfTopologyManager.close();
@@ -189,7 +196,7 @@ public class NetconfTopologyManagerTest {
         final DataObjectModification<Node> dataObjectModification1 = mock(DataObjectModification.class);
         doReturn(WRITE).when(dataObjectModification1).getModificationType();
         doReturn(node1).when(dataObjectModification1).getDataAfter();
-        doReturn(new InstanceIdentifier.IdentifiableItem<>(Node.class, new NodeKey(nodeId1)))
+        doReturn(InstanceIdentifier.IdentifiableItem.of(Node.class, new NodeKey(nodeId1)))
                 .when(dataObjectModification1).getIdentifier();
 
         final NetconfNode netconfNode2 = new NetconfNodeBuilder()
@@ -203,7 +210,7 @@ public class NetconfTopologyManagerTest {
         final DataObjectModification<Node> dataObjectModification2 = mock(DataObjectModification.class);
         doReturn(WRITE).when(dataObjectModification2).getModificationType();
         doReturn(node2).when(dataObjectModification2).getDataAfter();
-        doReturn(new InstanceIdentifier.IdentifiableItem<>(Node.class, new NodeKey(nodeId2)))
+        doReturn(InstanceIdentifier.IdentifiableItem.of(Node.class, new NodeKey(nodeId2)))
                 .when(dataObjectModification2).getIdentifier();
 
         final NetconfTopologyContext mockContext1 = mock(NetconfTopologyContext.class);
@@ -229,9 +236,9 @@ public class NetconfTopologyManagerTest {
                 .registerClusterSingletonService(mockContext2);
 
         netconfTopologyManager.onDataTreeChanged(Arrays.asList(
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId1), dataObjectModification1),
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId2), dataObjectModification2)));
 
         verify(clusterSingletonServiceProvider).registerClusterSingletonService(mockContext1);
@@ -258,9 +265,9 @@ public class NetconfTopologyManagerTest {
         doNothing().when(mockContext2).refresh(any());
 
         netconfTopologyManager.onDataTreeChanged(Arrays.asList(
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId1), dataObjectModification1),
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId2), dataObjectModification2)));
 
         ArgumentCaptor<NetconfTopologySetup> mockContext1Setup = ArgumentCaptor.forClass(NetconfTopologySetup.class);
@@ -278,7 +285,7 @@ public class NetconfTopologyManagerTest {
         doReturn(null).when(dataObjectModification1).getDataAfter();
 
         netconfTopologyManager.onDataTreeChanged(Arrays.asList(
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId1), dataObjectModification1)));
 
         verify(mockClusterRegistration1).close();
@@ -307,7 +314,7 @@ public class NetconfTopologyManagerTest {
         });
 
         netconfTopologyManager.onDataTreeChanged(Arrays.asList(
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId1), dataObjectModification1)));
 
         verify(clusterSingletonServiceProvider, times(2)).registerClusterSingletonService(newMockContext1);
@@ -346,7 +353,7 @@ public class NetconfTopologyManagerTest {
         final DataObjectModification<Node> dataObjectModification = mock(DataObjectModification.class);
         doReturn(WRITE).when(dataObjectModification).getModificationType();
         doReturn(node).when(dataObjectModification).getDataAfter();
-        doReturn(new InstanceIdentifier.IdentifiableItem<>(Node.class, new NodeKey(nodeId)))
+        doReturn(InstanceIdentifier.IdentifiableItem.of(Node.class, new NodeKey(nodeId)))
                 .when(dataObjectModification).getIdentifier();
 
         final NetconfTopologyContext mockContext = mock(NetconfTopologyContext.class);
@@ -358,7 +365,7 @@ public class NetconfTopologyManagerTest {
         netconfTopologyManager.init();
 
         netconfTopologyManager.onDataTreeChanged(Arrays.asList(
-                new CustomTreeModification(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                new CustomTreeModification(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
                         nodeInstanceId), dataObjectModification)));
 
         verify(clusterSingletonServiceProvider, times(3)).registerClusterSingletonService(mockContext);
@@ -379,13 +386,11 @@ public class NetconfTopologyManagerTest {
             this.rootNode = rootNode;
         }
 
-        @Nonnull
         @Override
         public DataTreeIdentifier<Node> getRootPath() {
             return rootPath;
         }
 
-        @Nonnull
         @Override
         public DataObjectModification<Node> getRootNode() {
             return rootNode;