Remove unused parameter in CallHomeSessionContext.java 79/101779/13
authorIvan Martiniak <ivan.martiniak@pantheon.tech>
Fri, 8 Jul 2022 12:24:51 +0000 (14:24 +0200)
committerIvan Martiniak <ivan.martiniak@pantheon.tech>
Tue, 30 Aug 2022 08:46:52 +0000 (08:46 +0000)
Parameter in the constructor 'final SocketAddress remoteAddress'
was marked as unused.
Method and tests related to this constructor were adjusted.

Resolved FIXME: Enable test
failureToOpenTheChannelShouldCauseTheSessionToClose().
Mock-maker-inline is used to be able to successfully run this test.

JIRA: NETCONF-681
Change-Id: Ifd8a76c6edcf801e432b7b925873806014b43b1a
Signed-off-by: Ivan Martiniak <ivan.martiniak@pantheon.tech>
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContext.java
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServer.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/CallHomeSessionContextTest.java
netconf/callhome-protocol/src/test/java/org/opendaylight/netconf/callhome/protocol/NetconfCallHomeServerTest.java
netconf/callhome-protocol/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker [new file with mode: 0644]

index 83a62f4fcdf9f9c2c3de563665a705c7aeb3c0c4..7fd5e6991dc558407cef2aa3ed7c6477b40d632b 100644 (file)
@@ -17,7 +17,6 @@ import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.security.PublicKey;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -54,7 +53,7 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
 
     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Passing 'this' around")
     CallHomeSessionContext(final ClientSession sshSession, final CallHomeAuthorization authorization,
-                           final SocketAddress remoteAddress, final Factory factory) {
+                           final Factory factory) {
         this.authorization = requireNonNull(authorization, "authorization");
         checkArgument(this.authorization.isServerAllowed(), "Server was not allowed.");
         this.factory = requireNonNull(factory);
@@ -182,17 +181,17 @@ class CallHomeSessionContext implements CallHomeProtocolSessionContext {
         }
 
         @Nullable CallHomeSessionContext createIfNotExists(final ClientSession sshSession,
-                final CallHomeAuthorization authorization, final SocketAddress remoteAddress) {
-            final var newSession = new CallHomeSessionContext(sshSession, authorization, remoteAddress, this);
+                                                           final CallHomeAuthorization authorization) {
+            final var newSession = new CallHomeSessionContext(sshSession, authorization, this);
             final var existing = sessions.putIfAbsent(newSession.getSessionId(), newSession);
             if (existing == null) {
-                // There was no mapping, but now there is. Associate the the context with the session.
+                // There was no mapping, but now there is. Associate the context with the session.
                 newSession.associate();
                 return newSession;
             }
 
             // We already have a mapping, do not create a new one. But also check if the current session matches
-            // the one stored in the session. This can happen during rekeying.
+            // the one stored in the session. This can happen during re-keying.
             return existing == CallHomeSessionContext.getFrom(sshSession) ? existing : null;
         }
 
index 8feecf2506db7aa60c3b5255f01c186b6c4c80c1..378ccbe2313d5432a8ef081e4fc5d9efead9a021 100644 (file)
@@ -157,7 +157,7 @@ public final class NetconfCallHomeServer implements AutoCloseable, ServerKeyVeri
             return false;
         }
 
-        if (sessionFactory.createIfNotExists(sshClientSession, authorization, remoteAddress) == null) {
+        if (sessionFactory.createIfNotExists(sshClientSession, authorization) == null) {
             // Session was not created, session with same name exists
             LOG.info("Incoming session {} was rejected. Session with same name {} is already active.", sshClientSession,
                 authorization.getSessionName());
index fd418064afa91812fc53853843c13cede99e6e15..0691c1cb77024f704a61e0d506e291c717e86e01 100644 (file)
@@ -26,7 +26,6 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.security.PublicKey;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.netconf.client.NetconfClientSessionListener;
@@ -101,7 +100,7 @@ public class CallHomeSessionContextTest {
     @Test
     public void theContextShouldBeSettableAndRetrievableAsASessionAttribute() {
         // when
-        instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
+        instance = realFactory.createIfNotExists(mockSession, mockAuth);
         // then
         assertNotNull(instance);
         verify(mockSession, times(1)).setAttribute(CallHomeSessionContext.SESSION_KEY, instance);
@@ -115,7 +114,7 @@ public class CallHomeSessionContextTest {
 
     @Test
     public void anAuthorizeActionShouldApplyToTheBoundSession() throws IOException {
-        instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
+        instance = realFactory.createIfNotExists(mockSession, mockAuth);
         // when
         Mockito.doReturn(null).when(mockSession).auth();
         instance.authorize();
@@ -133,29 +132,13 @@ public class CallHomeSessionContextTest {
 
         Mockito.doReturn(null).when(mockFuture).addListener(any(SshFutureListener.class));
         doNothing().when(mockChannelSubsystem).setStreaming(any(StreamingChannel.Streaming.class));
-        instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
+        instance = realFactory.createIfNotExists(mockSession, mockAuth);
         // when
         instance.openNetconfChannel();
         // then
         verify(mockFuture, times(1)).addListener(any(SshFutureListener.class));
     }
 
-    static class TestableContext extends CallHomeSessionContext {
-        MinaSshNettyChannel minaMock;
-
-        TestableContext(final ClientSession sshSession, final CallHomeAuthorization authorization,
-                        final InetSocketAddress address, final CallHomeSessionContext.Factory factory,
-                        final MinaSshNettyChannel minaMock) {
-            super(sshSession, authorization, address, factory);
-            this.minaMock = minaMock;
-        }
-
-        @Override
-        protected MinaSshNettyChannel newMinaSshNettyChannel(final ClientChannel netconfChannel) {
-            return minaMock;
-        }
-    }
-
     @Test
     public void openingTheChannelSuccessfullyNotifyTheChannelListener() {
         // given
@@ -180,7 +163,7 @@ public class CallHomeSessionContextTest {
         OpenFuture mockFuture = mock(OpenFuture.class);
         Mockito.doReturn(true).when(mockFuture).isOpened();
 
-        instance = new TestableContext(mockSession, mockAuth, address, mockFactory, mockMinaChannel);
+        instance = new TestableContext(mockSession, mockAuth, mockFactory, mockMinaChannel);
         SshFutureListener<OpenFuture> listener = instance.newSshFutureListener(mockChannel);
         // when
         listener.operationComplete(mockFuture);
@@ -190,11 +173,9 @@ public class CallHomeSessionContextTest {
     }
 
     @Test
-    @Ignore
-    // FIXME: enable this test
     public void failureToOpenTheChannelShouldCauseTheSessionToClose() {
         // given
-        instance = realFactory.createIfNotExists(mockSession, mockAuth, address);
+        instance = realFactory.createIfNotExists(mockSession, mockAuth);
         OpenFuture mockFuture = mock(OpenFuture.class);
         Mockito.doReturn(false).when(mockFuture).isOpened();
         Mockito.doReturn(new RuntimeException("test")).when(mockFuture).getException();
@@ -211,8 +192,23 @@ public class CallHomeSessionContextTest {
 
     @Test
     public void theContextConstructorShouldNotModifySession() {
-        instance = new CallHomeSessionContext(mockSession, mockAuth, address, realFactory);
+        instance = new CallHomeSessionContext(mockSession, mockAuth, realFactory);
         verify(mockSession, times(0)).setAttribute(any(), any());
         assertNull(CallHomeSessionContext.getFrom(mockSession));
     }
+
+    static class TestableContext extends CallHomeSessionContext {
+        MinaSshNettyChannel minaMock;
+
+        TestableContext(final ClientSession sshSession, final CallHomeAuthorization authorization,
+                        final CallHomeSessionContext.Factory factory, final MinaSshNettyChannel minaMock) {
+            super(sshSession, authorization, factory);
+            this.minaMock = minaMock;
+        }
+
+        @Override
+        protected MinaSshNettyChannel newMinaSshNettyChannel(final ClientChannel netconfChannel) {
+            return minaMock;
+        }
+    }
 }
index 250ab80bfa464e0adefeab8f15585ac67a11b527..136d5055aa81f20280120a0e0f10e121e21273dc 100644 (file)
@@ -139,7 +139,7 @@ public class NetconfCallHomeServerTest {
         Mockito.doReturn(true).when(mockAuth).isServerAllowed();
         Mockito.doReturn("some-session-name").when(mockAuth).getSessionName();
         Mockito.doReturn(mockAuth).when(mockCallHomeAuthProv).provideAuth(mockSocketAddr, mockPublicKey);
-        Mockito.doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth, mockSocketAddr);
+        Mockito.doReturn(null).when(mockFactory).createIfNotExists(mockClientSession, mockAuth);
 
         // expect
         assertFalse(instance.verifyServerKey(mockClientSession, mockSocketAddr, mockPublicKey));
diff --git a/netconf/callhome-protocol/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/netconf/callhome-protocol/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644 (file)
index 0000000..ca6ee9c
--- /dev/null
@@ -0,0 +1 @@
+mock-maker-inline
\ No newline at end of file