Move netconf-console to apps/
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / MountInstanceTest.java
index c59b9d8aea8ec34c914fea8e28b034d7b1be3d7a..80fe23c35f2cf0055a8c8aff53c1d7ed4506ad37 100644 (file)
@@ -8,35 +8,36 @@
 package org.opendaylight.netconf.sal.connect.netconf.sal;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.net.InetSocketAddress;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
 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.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class MountInstanceTest {
-    private static final Logger LOG = LoggerFactory.getLogger(MountInstanceTest.class);
-
     private static EffectiveModelContext SCHEMA_CONTEXT;
 
     @Mock
@@ -46,7 +47,7 @@ public class MountInstanceTest {
     @Mock
     private NetconfDataTreeService netconfService;
     @Mock
-    private DOMRpcService rpcService;
+    private Rpcs.Normalized rpcService;
     @Mock
     private NetconfDeviceNotificationService notificationService;
     @Mock
@@ -56,7 +57,7 @@ public class MountInstanceTest {
     @Mock
     private DOMNotification notification;
 
-    private NetconfDeviceSalProvider.MountInstance mountInstance;
+    private NetconfDeviceMount mountInstance;
 
     @BeforeClass
     public static void suiteSetUp() throws Exception {
@@ -65,20 +66,19 @@ public class MountInstanceTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
         when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
-
         when(mountPointBuilder.register()).thenReturn(registration);
-        mountInstance = new NetconfDeviceSalProvider.MountInstance(
-                service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
-    }
 
+        mountInstance = new NetconfDeviceMount(
+            new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)),
+            service, YangInstanceIdentifier.empty());
+    }
 
     @Test
     public void testOnTopologyDeviceConnected() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService,
-            notificationService, null);
-        verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, broker, null);
+        verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
         verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
         verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
@@ -86,9 +86,9 @@ public class MountInstanceTest {
 
     @Test
     public void testOnTopologyDeviceConnectedWithNetconfService() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, null, netconfService, rpcService,
-                notificationService, null);
-        verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, null, netconfService);
+        verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService);
         verify(mountPointBuilder).addService(DOMRpcService.class, rpcService);
         verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
@@ -96,32 +96,27 @@ public class MountInstanceTest {
 
     @Test
     public void testOnTopologyDeviceDisconnected() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService,
-            notificationService, null);
-        mountInstance.onTopologyDeviceDisconnected();
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, broker, null);
+        mountInstance.onDeviceDisconnected();
         verify(registration).close();
-        try {
-            mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService,
-                notificationService, null);
-        } catch (final IllegalStateException e) {
-            LOG.warn("Operation failed.", e);
-            Assert.fail("Topology registration still present after disconnect ");
-        }
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, broker, null);
     }
 
     @Test
     public void testClose() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService,
-            notificationService, null);
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, broker, null);
         mountInstance.close();
         verify(registration).close();
     }
 
     @Test
     public void testPublishNotification() {
-        mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, broker, null, rpcService,
-            notificationService, null);
-        verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT);
+        mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+            notificationService, broker, null);
+        verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
         verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
         mountInstance.publish(notification);
         verify(notificationService).publishNotification(notification);