You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2005/04/16 14:44:16 UTC

svn commit: r161564 - in jakarta/commons/proper/net/trunk/src: java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java

Author: scohen
Date: Sat Apr 16 05:44:15 2005
New Revision: 161564

URL: http://svn.apache.org/viewcvs?view=rev&rev=161564
Log:
Add supporting logic enabling test cases to be created for the Unix numeric date formats.

Modified:
    jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
    jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java

Modified: jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java?view=diff&r1=161563&r2=161564
==============================================================================
--- jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java (original)
+++ jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java Sat Apr 16 05:44:15 2005
@@ -44,6 +44,15 @@
     static final String DEFAULT_RECENT_DATE_FORMAT 
 		= "MMM d HH:mm"; //Nov 9 20:06
 
+    static final String NUMERIC_DATE_FORMAT 
+		= "yyyy-MM-dd HH:mm"; //2001-11-09 20:06
+
+    static final FTPClientConfig NUMERIC_DATE_CONFIG =
+        new FTPClientConfig(
+                FTPClientConfig.SYST_UNIX,
+                NUMERIC_DATE_FORMAT,
+                null, null, null, null);
+
     /**
      * this is the regular expression used by this parser.
      *
@@ -70,7 +79,7 @@
         + "(\\S+)\\s+"
         + "(?:(\\S+)\\s+)?"
         + "(\\d+)\\s+"
-		+ "(\\S+)\\s+(\\S+)\\s+((\\S+)(?:\\s+))?" /*the three parts of the date in any order*/
+		+ "(\\S+)\\s+(\\S+)\\s+((\\S+)(?:\\s+))?" /*the two or three parts of the date in any order*/
         + "(\\S+)(\\s*.*)";
 
 
@@ -259,5 +268,8 @@
                 DEFAULT_RECENT_DATE_FORMAT,
                 null, null, null);
     }
+    
+    
+    
 
 }

Modified: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java?view=diff&r1=161563&r2=161564
==============================================================================
--- jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java (original)
+++ jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java Sat Apr 16 05:44:15 2005
@@ -38,10 +38,11 @@
 			"-rw-r--r--   1 14       staff      119:26 Aug 22  2000 zxJDBC-1.2.3.zip",
 			"-rw-r--r--   1 ftp      no group    83853 Jan 22  2001 zxJDBC-1.2.4.tar.gz",
 			"-rw-r--r--   1ftp       nogroup    126552 Jan 22  2001 zxJDBC-1.2.4.zip",
+			"-rw-r--r--   1 root     root       190144 2001-04-27 zxJDBC-2.0.1b1.zip",
 			"-rw-r--r--   1 root     root       111325 Apr -7 18:79 zxJDBC-2.0.1b1.tar.gz" };
 
-	private static final String[] goodsamples = {
-
+	private static final String[] goodsamples = 
+	{
 			"-rw-r--r--   1 500      500            21 Aug  8 14:14 JB3-TES1.gz",
 			"-rwxr-xr-x   2 root     root         4096 Mar  2 15:13 zxbox",
 			"drwxr-xr-x   2 root     root         4096 Aug 24  2001 zxjdbc",
@@ -68,8 +69,8 @@
 			"-rwsr-sr--   1 500      500             0 Mar 25 08:23 testSuidExec",
 			"-rwsr-sr--   1 500      500             0 Mar 25 0:23 testSuidExec2",
 			"drwxrwx---+ 23 500     500    0 Jan 10 13:09 testACL",
-
-			"-rw-r--r--   1 1        3518644 May 25 12:12 std" };
+			"-rw-r--r--   1 1        3518644 May 25 12:12 std" 
+		};
 
 	/**
 	 * @see junit.framework.TestCase#TestCase(String)
@@ -91,6 +92,33 @@
 	protected String[] getGoodListing() {
 		return (goodsamples);
 	}
+	
+    /**
+     */
+    public void testNumericDateFormat()
+    {
+        String testNumericDF = 
+			"-rw-r-----   1 neeme neeme   346 2005-04-08 11:22 services.vsp";
+
+        UnixFTPEntryParser parser = 
+            new UnixFTPEntryParser(UnixFTPEntryParser.NUMERIC_DATE_CONFIG);
+        
+        FTPFile f = parser.parseFTPEntry(testNumericDF);
+        assertNotNull("Failed to parse " + testNumericDF,
+                      f);
+        
+        
+		Calendar cal = Calendar.getInstance();
+		cal.clear();
+		cal.set(Calendar.YEAR, 2005);
+		cal.set(Calendar.MONTH, Calendar.APRIL);
+
+		cal.set(Calendar.DATE, 8);
+		cal.set(Calendar.HOUR_OF_DAY, 11);
+		cal.set(Calendar.MINUTE, 22);
+		assertEquals(cal.getTime(), f.getTimestamp().getTime());
+    }
+
 
 	/**
 	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org