Move RemoteDeviceId
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / sal / KeepaliveSalFacadeResponseWaitingTest.java
index 371916784ab9c10a933f6640b3919ba6cc9bb0fa..b6da2275f6abe86c53fa9cf07559d3b1dc7a1e56 100644 (file)
@@ -7,47 +7,49 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.sal;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.after;
-import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps.getSourceNode;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
 
 import com.google.common.util.concurrent.SettableFuture;
 import java.net.InetSocketAddress;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
+import org.eclipse.jdt.annotation.NonNull;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.dom.api.DOMActionService;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
+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.netconf.sal.connect.netconf.NetconfDeviceSchema;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class KeepaliveSalFacadeResponseWaitingTest {
 
     private static final RemoteDeviceId REMOTE_DEVICE_ID =
             new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
-    private static final ContainerNode KEEPALIVE_PAYLOAD = NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
-            getSourceNode(NETCONF_RUNNING_QNAME), NetconfMessageTransformUtil.EMPTY_FILTER);
+    private static final @NonNull ContainerNode KEEPALIVE_PAYLOAD =
+        NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
+            getSourceNode(NETCONF_RUNNING_NODEID), NetconfMessageTransformUtil.EMPTY_FILTER);
 
     private KeepaliveSalFacade keepaliveSalFacade;
     private ScheduledExecutorService executorService;
@@ -55,25 +57,16 @@ public class KeepaliveSalFacadeResponseWaitingTest {
     private LocalNetconfSalFacade underlyingSalFacade;
 
     @Mock
-    private DOMRpcService deviceRpc;
-
-    @Mock
-    private DOMMountPointService mountPointService;
-
-    @Mock
-    private DataBroker dataBroker;
+    private Rpcs.Normalized deviceRpc;
 
     @Mock
     private NetconfDeviceCommunicator listener;
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         executorService = Executors.newScheduledThreadPool(2);
 
         underlyingSalFacade = new LocalNetconfSalFacade();
-        doNothing().when(listener).disconnect();
         keepaliveSalFacade = new KeepaliveSalFacade(REMOTE_DEVICE_ID, underlyingSalFacade, executorService, 2L, 10000L);
         keepaliveSalFacade.setListener(listener);
     }
@@ -95,12 +88,11 @@ public class KeepaliveSalFacadeResponseWaitingTest {
 
         //This settable future will be used to check the invokation of keepalive RPC. Should be never invoked.
         final SettableFuture<DOMRpcResult> keepaliveSettableFuture = SettableFuture.create();
-        doReturn(keepaliveSettableFuture).when(deviceRpc).invokeRpc(NETCONF_GET_CONFIG_QNAME, KEEPALIVE_PAYLOAD);
-        final DOMRpcResult keepaliveResult = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
-        keepaliveSettableFuture.set(keepaliveResult);
+        keepaliveSettableFuture.set(new DefaultDOMRpcResult(Builders.containerBuilder()
+            .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID)
+            .build()));
 
-        keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
+        keepaliveSalFacade.onDeviceConnected(null, null, new RemoteDeviceServices(deviceRpc, null));
 
         //Invoke general RPC on simulated local facade without args (or with null args). Will be returned
         //settableFuture variable without any set value. WaitingShaduler in keepalive sal facade should wait for any
@@ -114,19 +106,20 @@ public class KeepaliveSalFacadeResponseWaitingTest {
         verify(deviceRpc, after(2000).never()).invokeRpc(NETCONF_GET_CONFIG_QNAME, KEEPALIVE_PAYLOAD);
     }
 
-    private final class LocalNetconfSalFacade implements RemoteDeviceHandler<NetconfSessionPreferences> {
-
-        private DOMRpcService localDeviceRpc;
+    private static final class LocalNetconfSalFacade implements RemoteDeviceHandler {
+        private volatile Rpcs.Normalized rpcs;
 
         @Override
-        public void onDeviceConnected(final MountPointContext remoteSchemaContext,
-                final NetconfSessionPreferences netconfSessionPreferences, final DOMRpcService currentDeviceRpc,
-                final DOMActionService deviceAction) {
-            localDeviceRpc = currentDeviceRpc;
+        public void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
+                final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
+            final var newRpcs = services.rpcs();
+            assertThat(newRpcs, instanceOf(Rpcs.Normalized.class));
+            rpcs = (Rpcs.Normalized) newRpcs;
         }
 
         @Override
         public void onDeviceDisconnected() {
+            rpcs = null;
         }
 
         @Override
@@ -142,8 +135,9 @@ public class KeepaliveSalFacadeResponseWaitingTest {
         }
 
         public void invokeNullRpc() {
-            if (localDeviceRpc != null) {
-                localDeviceRpc.invokeRpc(null, null);
+            final var local = rpcs;
+            if (local != null) {
+                local.invokeRpc(null, null);
             }
         }
     }