Cleanup temporary test files 69/13069/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sun, 23 Nov 2014 23:41:57 +0000 (18:41 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 26 Nov 2014 19:27:45 +0000 (14:27 -0500)
A properly defined test should correctly cleanup after itself when the
tests have completed execution.

Change-Id: I9887558e698a2ee823a9f91727cde5eccc2348f2
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/ssh/authentication/SSHServerTest.java

index 3ea9a48a5d759bb9c2cecf830fdc4cd40e3c9bdf..16ea1b843102c46bc637d81a61653e6bf1e6710a 100644 (file)
@@ -38,6 +38,7 @@ public class FileStorageAdapterTest {
     @Before
     public void setUp() throws Exception {
         file = Files.createTempFile("testFilePersist", ".txt").toFile();
+        file.deleteOnExit();
         if (!file.exists()) {
             return;
         }
@@ -185,6 +186,7 @@ public class FileStorageAdapterTest {
     @Test
     public void testNoLastConfig() throws Exception {
         File file = Files.createTempFile("testFilePersist", ".txt").toFile();
+        file.deleteOnExit();
         if (!file.exists()) {
             return;
         }
index 6e265a44a50a55f18a3555c73ddd4afed91f13b5..fdc9a020065be13d5de4268abcfe65c35117a206 100644 (file)
@@ -25,6 +25,7 @@ import io.netty.channel.EventLoopGroup;
 import io.netty.channel.local.LocalAddress;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.GlobalEventExecutor;
+import java.io.File;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.nio.file.Files;
@@ -77,6 +78,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
     public static final String USERNAME = "user";
     public static final String PASSWORD = "pwd";
 
+    private File sshKeyPair;
     private SshProxyServer sshProxyServer;
 
     private ExecutorService nioExec;
@@ -85,6 +87,8 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
 
     @Before
     public void setUp() throws Exception {
+        sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile();
+        sshKeyPair.deleteOnExit();
         nioExec = Executors.newFixedThreadPool(1);
         clientGroup = new NioEventLoopGroup();
         minaTimerEx = Executors.newScheduledThreadPool(1);
@@ -99,7 +103,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
                 return true;
             }
         })
-                        .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()))
+                        .setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString()))
                         .setIdleTimeout(Integer.MAX_VALUE)
                         .createSshProxyServerConfiguration());
     }
index 34b236b4611f0e8586388e7ff22b1022effc2cd0..b682099595a3ce077a77b9c152a6de7d5a698c04 100644 (file)
@@ -19,6 +19,7 @@ import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.util.HashedWheelTimer;
+import java.io.File;
 import java.net.InetSocketAddress;
 import java.nio.file.Files;
 import java.util.concurrent.ExecutorService;
@@ -67,6 +68,8 @@ public class SSHTest {
 
     @Test
     public void test() throws Exception {
+        File sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile();
+        sshKeyPair.deleteOnExit();
         new Thread(new EchoServer(), "EchoServer").start();
 
         final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831);
@@ -77,7 +80,7 @@ public class SSHTest {
                     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());
+                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
 
         final EchoClientHandler echoClientHandler = connectClient(addr);
 
index 38aa2e71ace1850cdb42a02e7b018e09ab387170..297cf896da498bec242afa26d6b0c2037946d146 100644 (file)
@@ -15,6 +15,7 @@ import static org.mockito.Mockito.doReturn;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import java.net.InetSocketAddress;
+import java.io.File;
 import java.nio.file.Files;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -49,6 +50,7 @@ public class SSHServerTest {
     private static final int PORT = 1830;
     private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
 
+    private File sshKeyPair;
     private SshProxyServer server;
 
     @Mock
@@ -59,6 +61,9 @@ 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());
@@ -74,7 +79,7 @@ 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());
+                }).setKeyPairProvider(new PEMGeneratorHostKeyProvider(sshKeyPair.toPath().toAbsolutePath().toString())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
         logger.info("SSH server started on " + PORT);
     }