1 16 package org.apache.commons.net.ftp.parser; 17 18 import java.util.Calendar ; 19 20 import junit.framework.TestSuite; 21 import org.apache.commons.net.ftp.FTPFile; 22 import org.apache.commons.net.ftp.FTPFileEntryParser; 23 24 28 public class NTFTPEntryParserTest extends CompositeFTPParseTestFramework 29 { 30 31 private static final String [][] goodsamples = { 32 { 33 "05-26-95 10:57AM 143712 $LDR$", 34 "05-20-97 03:31PM 681 .bash_history", 35 "12-05-96 05:03PM <DIR> absoft2", 36 "11-14-97 04:21PM 953 AUDITOR3.INI", 37 "05-22-97 08:08AM 828 AUTOEXEC.BAK", 38 "01-22-98 01:52PM 795 AUTOEXEC.BAT", 39 "05-13-97 01:46PM 828 AUTOEXEC.DOS", 40 "12-03-96 06:38AM 403 AUTOTOOL.LOG", 41 "12-03-96 06:38AM <DIR> 123xyz", 42 "01-20-97 03:48PM <DIR> bin", 43 "05-26-1995 10:57AM 143712 $LDR$", 44 }, 45 { 46 "-rw-r--r-- 1 root root 111325 Apr 27 2001 zxJDBC-2.0.1b1.tar.gz", 47 "-rw-r--r-- 1 root root 190144 Apr 27 2001 zxJDBC-2.0.1b1.zip", 48 "-rwxr-xr-x 2 500 500 166 Nov 2 2001 73131-testtes1.afp", 49 "-rw-r--r-- 1 500 500 166 Nov 9 2001 73131-testtes1.AFP", 50 } 51 }; 52 53 private static final String [][] badsamples = 54 { 55 { 56 "20-05-97 03:31PM 681 .bash_history", 57 "drwxr-xr-x 2 root 99 4096 Feb 23 30:01 zzplayer", 58 "12-05-96 17:03 <DIR> absoft2", 59 "05-22-97 08:08 828 AUTOEXEC.BAK", 60 " 0 DIR 05-19-97 12:56 local", 61 " 0 DIR 05-12-97 16:52 Maintenance Desktop", 62 }, 63 { 64 "20-05-97 03:31PM 681 .bash_history", 65 "drwxr-xr-x 2 root 99 4096Feb 23 30:01 zzplayer", 66 "12-05-96 17:03 <DIR> absoft2", 67 "05-22-97 08:08 828 AUTOEXEC.BAK", 68 " 0 DIR 05-19-97 12:56 local", 69 " 0 DIR 05-12-97 16:52 Maintenance Desktop", 70 } 71 }; 72 73 private static final String directoryBeginningWithNumber = 74 "12-03-96 06:38AM <DIR> 123xyz"; 75 76 77 80 public NTFTPEntryParserTest (String name) 81 { 82 super(name); 83 } 84 85 88 protected String [][] getGoodListings() 89 { 90 return goodsamples; 91 } 92 93 96 protected String [][] getBadListings() 97 { 98 return badsamples; 99 } 100 101 104 protected FTPFileEntryParser getParser() 105 { 106 return new CompositeFileEntryParser(new FTPFileEntryParser[] 107 { 108 new NTFTPEntryParser(), 109 new UnixFTPEntryParser() 110 111 }); 112 } 113 114 119 public static TestSuite suite() 120 { 121 return(new TestSuite(NTFTPEntryParserTest.class)); 122 } 123 124 127 public void testParseFieldsOnDirectory() throws Exception 128 { 129 FTPFile dir = getParser().parseFTPEntry("12-05-96 05:03PM <DIR> absoft2"); 130 assertNotNull("Could not parse entry.", dir); 131 assertEquals("Thu Dec 05 17:03:00 1996", 132 df.format(dir.getTimestamp().getTime())); 133 assertTrue("Should have been a directory.", 134 dir.isDirectory()); 135 assertEquals("absoft2", dir.getName()); 136 assertEquals(0, dir.getSize()); 137 138 dir = getParser().parseFTPEntry("12-03-96 06:38AM <DIR> 123456"); 139 assertNotNull("Could not parse entry.", dir); 140 assertTrue("Should have been a directory.", 141 dir.isDirectory()); 142 assertEquals("123456", dir.getName()); 143 assertEquals(0, dir.getSize()); 144 145 } 146 147 150 public void testParseFieldsOnFile() throws Exception 151 { 152 FTPFile f = getParser().parseFTPEntry("05-22-97 12:08AM 5000000000 AUTOEXEC.BAK"); 153 assertNotNull("Could not parse entry.", f); 154 assertEquals("Thu May 22 00:08:00 1997", 155 df.format(f.getTimestamp().getTime())); 156 assertTrue("Should have been a file.", 157 f.isFile()); 158 assertEquals("AUTOEXEC.BAK", f.getName()); 159 assertEquals(5000000000L, f.getSize()); 160 161 164 f = getParser().parseFTPEntry( 165 "-rw-rw-r-- 1 mqm mqm 17707 Mar 12 3:33 killmq.sh.log"); 166 assertNotNull("Could not parse entry.", f); 167 Calendar cal = Calendar.getInstance(); 168 cal.setTime(f.getTimestamp().getTime()); 169 assertEquals("hour", 3, cal.get(Calendar.HOUR)); 170 assertTrue("Should have been a file.", 171 f.isFile()); 172 assertEquals(17707, f.getSize()); 173 174 175 176 177 178 } 179 180 181 protected void doAdditionalGoodTests(String test, FTPFile f) 182 { 183 if (test.indexOf("<DIR>") >= 0) 184 { 185 assertEquals("directory.type", 186 FTPFile.DIRECTORY_TYPE, f.getType()); 187 } 188 } 189 190 197 public void testDirectoryBeginningWithNumber() throws Exception 198 { 199 FTPFile f = getParser().parseFTPEntry(directoryBeginningWithNumber); 200 assertEquals("name", "123xyz", f.getName()); 201 } 202 } 203 | Popular Tags |