Further rework of base schemas
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / NetconfNodeManagerTest.java
index 873038de33d716353a71c7dbd67698bc4f3d5dab..d9cfec0b1d4295c0d45bff11eef85763aa744a7e 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.netconf.topology.singleton.impl;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.after;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -19,9 +19,9 @@ import static org.mockito.Mockito.timeout;
 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.actor.ActorSystem;
 import akka.actor.Props;
@@ -49,15 +49,16 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
-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.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+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.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
@@ -83,8 +84,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
@@ -96,7 +98,7 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
  *
  * @author Thomas Pantelis
  */
-public class NetconfNodeManagerTest {
+public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
     private static final String ACTOR_SYSTEM_NAME = "test";
     private static final RemoteDeviceId DEVICE_ID = new RemoteDeviceId("device", new InetSocketAddress(65535));
     private static final List<SourceIdentifier> SOURCE_IDENTIFIERS =
@@ -120,11 +122,14 @@ public class NetconfNodeManagerTest {
     @Mock
     private DOMRpcService mockRpcService;
 
+    @Mock
+    private DOMActionService mockActionService;
+
     @Mock
     private NetconfDeviceSchemasResolver mockSchemasResolver;
 
     @Mock
-    private SchemaContextFactory mockSchemaContextFactory;
+    private EffectiveModelContextFactory mockSchemaContextFactory;
 
     private ActorSystem slaveSystem;
     private ActorSystem masterSystem;
@@ -163,7 +168,7 @@ public class NetconfNodeManagerTest {
         NetconfTopologySetup masterSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
                 .setActorSystem(masterSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
                         new NetconfDevice.SchemaResourcesDTO(masterSchemaRepository, masterSchemaRepository,
-                                mockSchemaContextFactory, mockSchemasResolver)).build();
+                                mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
 
         testMasterActorRef = TestActorRef.create(masterSystem, Props.create(TestMasterActor.class, masterSetup,
                 DEVICE_ID, responseTimeout, mockMountPointService).withDispatcher(Dispatchers.DefaultDispatcherId()),
@@ -176,7 +181,7 @@ public class NetconfNodeManagerTest {
         NetconfTopologySetup slaveSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
                 .setActorSystem(slaveSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
                         new NetconfDevice.SchemaResourcesDTO(slaveSchemaRepository, slaveSchemaRepository,
-                                mockSchemaContextFactory, mockSchemasResolver)).build();
+                                mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
 
         netconfNodeManager = new NetconfNodeManager(slaveSetup, DEVICE_ID, responseTimeout,
                 mockMountPointService);
@@ -186,8 +191,8 @@ public class NetconfNodeManagerTest {
 
     @After
     public void teardown() {
-        TestKit.shutdownActorSystem(slaveSystem, Boolean.TRUE);
-        TestKit.shutdownActorSystem(masterSystem, Boolean.TRUE);
+        TestKit.shutdownActorSystem(slaveSystem, true);
+        TestKit.shutdownActorSystem(masterSystem, true);
     }
 
     @SuppressWarnings("unchecked")
@@ -211,7 +216,7 @@ public class NetconfNodeManagerTest {
         // Connected. Expect the slave mount point created and registered.
 
         final NetconfNode netconfNode = newNetconfNode();
-        final Node node = new NodeBuilder().setNodeId(nodeId).addAugmentation(NetconfNode.class, netconfNode).build();
+        final Node node = new NodeBuilder().setNodeId(nodeId).addAugmentation(netconfNode).build();
 
         DataObjectModification<Node> mockDataObjModification = mock(DataObjectModification.class);
         doReturn(Iterables.getLast(nodeListPath.getPathArguments())).when(mockDataObjModification).getIdentifier();
@@ -219,7 +224,7 @@ public class NetconfNodeManagerTest {
         doReturn(node).when(mockDataObjModification).getDataAfter();
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointBuilder, timeout(5000)).register();
@@ -235,7 +240,7 @@ public class NetconfNodeManagerTest {
         doReturn(null).when(mockDataObjModification).getDataAfter();
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointReg, timeout(5000)).close();
@@ -249,7 +254,7 @@ public class NetconfNodeManagerTest {
         doReturn(node).when(mockDataObjModification).getDataAfter();
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointBuilder, timeout(5000)).register();
@@ -262,7 +267,7 @@ public class NetconfNodeManagerTest {
         doReturn(node).when(mockDataObjModification).getDataBefore();
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointReg, timeout(5000)).close();
@@ -274,16 +279,17 @@ public class NetconfNodeManagerTest {
         setupMountPointMocks();
 
         final Node updatedNode = new NodeBuilder().setNodeId(nodeId)
-                .addAugmentation(NetconfNode.class, new NetconfNodeBuilder(netconfNode)
-                        .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.UnableToConnect)
-                        .build()).build();
+                .addAugmentation(new NetconfNodeBuilder(netconfNode)
+                    .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.UnableToConnect)
+                    .build())
+                .build();
 
         doReturn(SUBTREE_MODIFIED).when(mockDataObjModification).getModificationType();
         doReturn(node).when(mockDataObjModification).getDataBefore();
         doReturn(updatedNode).when(mockDataObjModification).getDataAfter();
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointReg, timeout(5000)).close();
@@ -303,7 +309,7 @@ public class NetconfNodeManagerTest {
                 nodeKey, topologyId);
 
         final NetconfNode netconfNode = newNetconfNode();
-        final Node node = new NodeBuilder().setNodeId(nodeId).addAugmentation(NetconfNode.class, netconfNode).build();
+        final Node node = new NodeBuilder().setNodeId(nodeId).addAugmentation(netconfNode).build();
 
         DataObjectModification<Node> mockDataObjModification = mock(DataObjectModification.class);
         doReturn(Iterables.getLast(nodeListPath.getPathArguments())).when(mockDataObjModification).getIdentifier();
@@ -313,7 +319,7 @@ public class NetconfNodeManagerTest {
         // First try the registration where the perceived master hasn't been initialized as the master.
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         verify(mockMountPointBuilder, after(1000).never()).register();
@@ -328,7 +334,7 @@ public class NetconfNodeManagerTest {
                 yangTextSchemaSourceRequestFuture);
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         yangTextSchemaSourceRequestFuture.get(5, TimeUnit.SECONDS);
@@ -344,7 +350,7 @@ public class NetconfNodeManagerTest {
                 askForMasterMountPointFuture);
 
         netconfNodeManager.onDataTreeChanged(Collections.singletonList(
-                new NetconfTopologyManagerTest.CustomTreeModification(new DataTreeIdentifier<>(
+                new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
         askForMasterMountPointFuture.get(5, TimeUnit.SECONDS);
@@ -359,7 +365,7 @@ public class NetconfNodeManagerTest {
     private NetconfNode newNetconfNode() {
         return new NetconfNodeBuilder()
                 .setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1"))))
-                .setPort(new PortNumber(9999))
+                .setPort(new PortNumber(Uint16.valueOf(9999)))
                 .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.Connected)
                 .setClusteredConnectionStatus(new ClusteredConnectionStatusBuilder()
                         .setNetconfMasterNode(masterAddress).build())
@@ -382,7 +388,7 @@ public class NetconfNodeManagerTest {
         TestKit kit = new TestKit(masterSystem);
 
         testMasterActorRef.tell(new CreateInitialMasterActorData(mockDeviceDataBroker, SOURCE_IDENTIFIERS,
-                mockRpcService), kit.getRef());
+                mockRpcService, mockActionService), kit.getRef());
 
         kit.expectMsgClass(MasterActorDataInitialized.class);
     }
@@ -390,15 +396,14 @@ public class NetconfNodeManagerTest {
     private static class TestMasterActor extends NetconfNodeActor {
         final Map<Class<?>, CompletableFuture<? extends Object>> messagesToDrop = new ConcurrentHashMap<>();
 
-        TestMasterActor(NetconfTopologySetup setup, RemoteDeviceId deviceId, Timeout actorResponseWaitTime,
-                DOMMountPointService mountPointService) {
-            super(setup, deviceId, setup.getSchemaResourcesDTO().getSchemaRegistry(),
-                    setup.getSchemaResourcesDTO().getSchemaRepository(), actorResponseWaitTime, mountPointService);
+        TestMasterActor(final NetconfTopologySetup setup, final RemoteDeviceId deviceId,
+                final Timeout actorResponseWaitTime, final DOMMountPointService mountPointService) {
+            super(setup, deviceId, actorResponseWaitTime, mountPointService);
         }
 
         @SuppressWarnings({ "rawtypes", "unchecked" })
         @Override
-        public void handleReceive(Object message) throws Exception {
+        public void handleReceive(final Object message) {
             CompletableFuture dropFuture = messagesToDrop.remove(message.getClass());
             if (dropFuture != null) {
                 dropFuture.complete(message);