You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/01/20 02:28:34 UTC

svn commit: r1653174 - in /commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp: TFTPServerPathTest.java TFTPTest.java

Author: sebb
Date: Tue Jan 20 01:28:33 2015
New Revision: 1653174

URL: http://svn.apache.org/r1653174
Log:
Use constant for port number
Use different ports for tests that might run consecutively

Modified:
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPTest.java

Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java?rev=1653174&r1=1653173&r2=1653174&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java Tue Jan 20 01:28:33 2015
@@ -34,13 +34,14 @@ import junit.framework.TestCase;
  */
 public class TFTPServerPathTest extends TestCase
 {
+    private static final int SERVER_PORT = 6901;
     String filePrefix = "tftp-";
     File serverDirectory = new File(System.getProperty("java.io.tmpdir"));
 
     public void testReadOnly() throws IOException
     {
         // Start a read-only server
-        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, 6900,
+        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, SERVER_PORT,
                 ServerMode.GET_ONLY, null, null);
 
         // Create our TFTP instance to handle the file transfer.
@@ -61,7 +62,7 @@ public class TFTPServerPathTest extends
 
         FileOutputStream output = new FileOutputStream(out);
 
-        tftp.receiveFile(file.getName(), TFTP.BINARY_MODE, output, "localhost", 6900);
+        tftp.receiveFile(file.getName(), TFTP.BINARY_MODE, output, "localhost", SERVER_PORT);
         output.close();
 
         assertTrue("file not created", out.exists());
@@ -71,7 +72,7 @@ public class TFTPServerPathTest extends
         FileInputStream fis = new FileInputStream(file);
         try
         {
-            tftp.sendFile(out.getName(), TFTP.BINARY_MODE, fis, "localhost", 6900);
+            tftp.sendFile(out.getName(), TFTP.BINARY_MODE, fis, "localhost", SERVER_PORT);
             fail("Server allowed write");
         }
         catch (IOException e)
@@ -86,7 +87,7 @@ public class TFTPServerPathTest extends
     public void testWriteOnly() throws IOException
     {
         // Start a write-only server
-        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, 6900,
+        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, SERVER_PORT,
                 ServerMode.PUT_ONLY, null, null);
 
         // Create our TFTP instance to handle the file transfer.
@@ -108,7 +109,7 @@ public class TFTPServerPathTest extends
 
         try
         {
-            tftp.receiveFile(file.getName(), TFTP.BINARY_MODE, output, "localhost", 6900);
+            tftp.receiveFile(file.getName(), TFTP.BINARY_MODE, output, "localhost", SERVER_PORT);
             fail("Server allowed read");
         }
         catch (IOException e)
@@ -119,7 +120,7 @@ public class TFTPServerPathTest extends
         out.delete();
 
         FileInputStream fis = new FileInputStream(file);
-        tftp.sendFile(out.getName(), TFTP.BINARY_MODE, fis, "localhost", 6900);
+        tftp.sendFile(out.getName(), TFTP.BINARY_MODE, fis, "localhost", SERVER_PORT);
 
         fis.close();
 
@@ -134,7 +135,7 @@ public class TFTPServerPathTest extends
     public void testWriteOutsideHome() throws IOException
     {
         // Start a server
-        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, 6900,
+        TFTPServer tftpS = new TFTPServer(serverDirectory, serverDirectory, SERVER_PORT,
                 ServerMode.GET_AND_PUT, null, null);
 
         // Create our TFTP instance to handle the file transfer.
@@ -149,7 +150,7 @@ public class TFTPServerPathTest extends
         FileInputStream fis = new FileInputStream(file);
         try
         {
-            tftp.sendFile("../foo", TFTP.BINARY_MODE, fis, "localhost", 6900);
+            tftp.sendFile("../foo", TFTP.BINARY_MODE, fis, "localhost", SERVER_PORT);
             fail("Server allowed write!");
         }
         catch (IOException e)

Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPTest.java?rev=1653174&r1=1653173&r2=1653174&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPTest.java Tue Jan 20 01:28:33 2015
@@ -38,6 +38,7 @@ import junit.framework.TestCase;
  */
 public class TFTPTest extends TestCase
 {
+    private static final int SERVER_PORT = 6902;
     private static TFTPServer tftpS;
     private static final File serverDirectory = new File(System.getProperty("java.io.tmpdir"));
     private static final String filePrefix = "tftp-";
@@ -60,7 +61,7 @@ public class TFTPTest extends TestCase
             files[7] = createFile(new File(serverDirectory, filePrefix + "huge.txt"), 37000 * 1024);
 
             // Start the server
-            tftpS = new TFTPServer(serverDirectory, serverDirectory, 6900, ServerMode.GET_AND_PUT,
+            tftpS = new TFTPServer(serverDirectory, serverDirectory, SERVER_PORT, ServerMode.GET_AND_PUT,
                     null, null);
             tftpS.setSocketTimeout(2000);
         }
@@ -177,7 +178,7 @@ public class TFTPTest extends TestCase
 
         FileOutputStream output = new FileOutputStream(out);
 
-        tftp.receiveFile(file.getName(), mode, output, "localhost", 6900);
+        tftp.receiveFile(file.getName(), mode, output, "localhost", SERVER_PORT);
         output.close();
 
         assertTrue("file not created", out.exists());
@@ -200,7 +201,7 @@ public class TFTPTest extends TestCase
         assertTrue("Couldn't clear output location", !in.exists());
 
         FileInputStream fis = new FileInputStream(file);
-        tftp.sendFile(in.getName(), mode, fis, "localhost", 6900);
+        tftp.sendFile(in.getName(), mode, fis, "localhost", SERVER_PORT);
         fis.close();
 
         // need to give the server a bit of time to receive our last packet, and