Merge "Optimize xsql's use of collections"
[controller.git] / opendaylight / netconf / netconf-ssh / src / test / java / org / opendaylight / controller / netconf / ssh / authentication / SSHServerTest.java
index 38aa2e71ace1850cdb42a02e7b018e09ab387170..7a76285dd2a125ac7cbabbf72b69ff90166ac5b9 100644 (file)
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.doReturn;
 
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
+import java.io.File;
 import java.net.InetSocketAddress;
 import java.nio.file.Files;
 import java.util.concurrent.ExecutorService;
@@ -47,8 +48,9 @@ public class SSHServerTest {
     private static final String PASSWORD = "netconf";
     private static final String HOST = "127.0.0.1";
     private static final int PORT = 1830;
-    private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SSHServerTest.class);
 
+    private File sshKeyPair;
     private SshProxyServer server;
 
     @Mock
@@ -59,12 +61,15 @@ public class SSHServerTest {
 
     @Before
     public void setUp() throws Exception {
+        sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile();
+        sshKeyPair.deleteOnExit();
+
         MockitoAnnotations.initMocks(this);
         doReturn(null).when(mockedContext).createFilter(anyString());
         doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString());
         doReturn(new ServiceReference[0]).when(mockedContext).getServiceReferences(anyString(), anyString());
 
-        logger.info("Creating SSH server");
+        LOG.info("Creating SSH server");
 
         final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
         server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
@@ -74,8 +79,8 @@ public class SSHServerTest {
                     public boolean authenticate(final String username, final String password, final ServerSession session) {
                         return true;
                     }
-                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
-        logger.info("SSH server started on " + PORT);
+                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
+        LOG.info("SSH server started on {}", PORT);
     }
 
     @Test