Split out odl-netconf-device.yang
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / NetconfNodeManagerTest.java
index d9cfec0b1d4295c0d45bff11eef85763aa744a7e..d49aadb427a2c7efdc50f1041dc93fd30191342e 100644 (file)
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.reset;
 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.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;
@@ -30,13 +29,11 @@ import akka.dispatch.Dispatchers;
 import akka.testkit.TestActorRef;
 import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.io.ByteSource;
 import com.google.common.util.concurrent.Futures;
 import com.typesafe.config.ConfigFactory;
 import java.net.InetSocketAddress;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
@@ -48,18 +45,23 @@ import java.util.stream.Collectors;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 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.dom.api.NetconfDataTreeService;
 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor;
@@ -73,10 +75,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.ClusteredConnectionStatusBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.ConnectionOper.ConnectionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.connection.oper.ClusteredConnectionStatusBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 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;
@@ -86,23 +88,22 @@ 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.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
 /**
  * Unit tests for NetconfNodeManager.
  *
  * @author Thomas Pantelis
  */
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 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 =
-            ImmutableList.of(RevisionSourceIdentifier.create("testID"));
+    private static final List<SourceIdentifier> SOURCE_IDENTIFIERS = List.of(new SourceIdentifier("testID"));
 
     @Mock
     private DOMMountPointService mockMountPointService;
@@ -116,14 +117,17 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
     @Mock
     private DataBroker mockDataBroker;
 
+    @Mock
+    private NetconfDataTreeService netconfService;
+
     @Mock
     private DOMDataBroker mockDeviceDataBroker;
 
     @Mock
-    private DOMRpcService mockRpcService;
+    private Rpcs.Normalized mockRpcService;
 
     @Mock
-    private DOMActionService mockActionService;
+    private Actions.Normalized mockActionService;
 
     @Mock
     private NetconfDeviceSchemasResolver mockSchemasResolver;
@@ -139,8 +143,6 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
     @Before
     public void setup() {
-        initMocks(this);
-
         final Timeout responseTimeout = Timeout.apply(1, TimeUnit.SECONDS);
 
         slaveSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, ConfigFactory.load().getConfig("Slave"));
@@ -150,18 +152,18 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
         SharedSchemaRepository masterSchemaRepository = new SharedSchemaRepository("master");
         masterSchemaRepository.registerSchemaSourceListener(
-                TextToASTTransformer.create(masterSchemaRepository, masterSchemaRepository));
+                TextToIRTransformer.create(masterSchemaRepository, masterSchemaRepository));
 
-        String yangTemplate =
-                  "module ID {"
-                + "  namespace \"ID\";"
-                + "  prefix ID;"
-                + "}";
+        final String yangTemplate = """
+            module ID {\
+              namespace "ID";\
+              prefix ID;\
+            }""";
 
         SOURCE_IDENTIFIERS.stream().map(
             sourceId -> masterSchemaRepository.registerSchemaSource(
                 id -> Futures.immediateFuture(YangTextSchemaSource.delegateForByteSource(id,
-                        ByteSource.wrap(yangTemplate.replaceAll("ID", id.getName()).getBytes(UTF_8)))),
+                        ByteSource.wrap(yangTemplate.replaceAll("ID", id.name().getLocalName()).getBytes(UTF_8)))),
                 PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class, 1)))
         .collect(Collectors.toList());
 
@@ -176,7 +178,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
         SharedSchemaRepository slaveSchemaRepository = new SharedSchemaRepository("slave");
         slaveSchemaRepository.registerSchemaSourceListener(
-                TextToASTTransformer.create(slaveSchemaRepository, slaveSchemaRepository));
+                TextToIRTransformer.create(slaveSchemaRepository, slaveSchemaRepository));
 
         NetconfTopologySetup slaveSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
                 .setActorSystem(slaveSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
@@ -223,7 +225,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         doReturn(WRITE).when(mockDataObjModification).getModificationType();
         doReturn(node).when(mockDataObjModification).getDataAfter();
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -236,10 +238,8 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         // Notify that the NetconfNode operational state was deleted. Expect the slave mount point closed.
 
         doReturn(DELETE).when(mockDataObjModification).getModificationType();
-        doReturn(node).when(mockDataObjModification).getDataBefore();
-        doReturn(null).when(mockDataObjModification).getDataAfter();
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -253,7 +253,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         doReturn(null).when(mockDataObjModification).getDataBefore();
         doReturn(node).when(mockDataObjModification).getDataAfter();
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -266,7 +266,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
         doReturn(node).when(mockDataObjModification).getDataBefore();
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -276,11 +276,12 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         // Notify that the NetconfNode operational state was changed to UnableToConnect. Expect the slave mount point
         // closed.
 
-        setupMountPointMocks();
+        reset(mockMountPointService, mockMountPointBuilder, mockMountPointReg);
+        doNothing().when(mockMountPointReg).close();
 
         final Node updatedNode = new NodeBuilder().setNodeId(nodeId)
                 .addAugmentation(new NetconfNodeBuilder(netconfNode)
-                    .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.UnableToConnect)
+                    .setConnectionStatus(ConnectionStatus.UnableToConnect)
                     .build())
                 .build();
 
@@ -288,7 +289,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         doReturn(node).when(mockDataObjModification).getDataBefore();
         doReturn(updatedNode).when(mockDataObjModification).getDataAfter();
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -318,7 +319,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
         // First try the registration where the perceived master hasn't been initialized as the master.
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -333,7 +334,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         testMasterActorRef.underlyingActor().messagesToDrop.put(YangTextSchemaSourceRequest.class,
                 yangTextSchemaSourceRequestFuture);
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -349,7 +350,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         testMasterActorRef.underlyingActor().messagesToDrop.put(AskForMasterMountPoint.class,
                 askForMasterMountPointFuture);
 
-        netconfNodeManager.onDataTreeChanged(Collections.singletonList(
+        netconfNodeManager.onDataTreeChanged(List.of(
                 new NetconfTopologyManagerTest.CustomTreeModification(DataTreeIdentifier.create(
                         LogicalDatastoreType.OPERATIONAL, nodeListPath), mockDataObjModification)));
 
@@ -357,7 +358,8 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         verify(mockMountPointReg, timeout(5000)).close();
         verify(mockMountPointBuilder, timeout(5000)).register();
 
-        setupMountPointMocks();
+        reset(mockMountPointService, mockMountPointBuilder, mockMountPointReg);
+        doNothing().when(mockMountPointReg).close();
         netconfNodeManager.close();
         verify(mockMountPointReg, timeout(5000)).close();
     }
@@ -366,7 +368,7 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
         return new NetconfNodeBuilder()
                 .setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1"))))
                 .setPort(new PortNumber(Uint16.valueOf(9999)))
-                .setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.Connected)
+                .setConnectionStatus(ConnectionStatus.Connected)
                 .setClusteredConnectionStatus(new ClusteredConnectionStatusBuilder()
                         .setNetconfMasterNode(masterAddress).build())
                 .build();
@@ -374,21 +376,15 @@ public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
 
     private void setupMountPointMocks() {
         reset(mockMountPointService, mockMountPointBuilder, mockMountPointReg);
-
         doNothing().when(mockMountPointReg).close();
-
-        doReturn(mockMountPointBuilder).when(mockMountPointBuilder).addInitialSchemaContext(any());
-        doReturn(mockMountPointBuilder).when(mockMountPointBuilder).addService(any(), any());
         doReturn(mockMountPointReg).when(mockMountPointBuilder).register();
-
         doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
     }
 
     private void initializeMaster() {
         TestKit kit = new TestKit(masterSystem);
-
-        testMasterActorRef.tell(new CreateInitialMasterActorData(mockDeviceDataBroker, SOURCE_IDENTIFIERS,
-                mockRpcService, mockActionService), kit.getRef());
+        testMasterActorRef.tell(new CreateInitialMasterActorData(mockDeviceDataBroker, netconfService,
+            SOURCE_IDENTIFIERS, new RemoteDeviceServices(mockRpcService, mockActionService)), kit.getRef());
 
         kit.expectMsgClass(MasterActorDataInitialized.class);
     }