1 16 package org.apache.commons.net.ftp.parser; 17 18 import java.util.Calendar ; 19 20 import junit.framework.TestSuite; 21 22 import org.apache.commons.net.ftp.FTPFile; 23 import org.apache.commons.net.ftp.FTPFileEntryParser; 24 25 31 public class EnterpriseUnixFTPEntryParserTest extends FTPParseTestFramework 32 { 33 34 private static final String [] BADSAMPLES = 35 { 36 "zrwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox", 37 "dxrwr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc", 38 "drwxr-xr-x 2 root root 4096 Jam 4 00:03 zziplib", 39 "drwxr-xr-x 2 root 99 4096 Feb 23 30:01 zzplayer", 40 "drwxr-xr-x 2 root root 4096 Aug 36 2001 zztpp", 41 "-rw-r--r-- 1 14 staff 80284 Aug 22 zxJDBC-1.2.3.tar.gz", 42 "-rw-r--r-- 1 14 staff 119:26 Aug 22 2000 zxJDBC-1.2.3.zip", 43 "-rw-r--r-- 1 ftp no group 83853 Jan 22 2001 zxJDBC-1.2.4.tar.gz", 44 "-rw-r--r-- 1ftp nogroup 126552 Jan 22 2001 zxJDBC-1.2.4.zip", 45 "-rw-r--r-- 1 root root 111325 Apr -7 18:79 zxJDBC-2.0.1b1.tar.gz", 46 "drwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox", 47 "drwxr-xr-x 1 usernameftp 512 Jan 29 23:32 prog", 48 "drwxr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc", 49 "drwxr-xr-x 2 root root 4096 Jan 4 00:03 zziplib", 50 "drwxr-xr-x 2 root 99 4096 Feb 23 2001 zzplayer", 51 "drwxr-xr-x 2 root root 4096 Aug 6 2001 zztpp", 52 "-rw-r--r-- 1 14 staff 80284 Aug 22 2000 zxJDBC-1.2.3.tar.gz", 53 "-rw-r--r-- 1 14 staff 119926 Aug 22 2000 zxJDBC-1.2.3.zip", 54 "-rw-r--r-- 1 ftp nogroup 83853 Jan 22 2001 zxJDBC-1.2.4.tar.gz", 55 "-rw-r--r-- 1 ftp nogroup 126552 Jan 22 2001 zxJDBC-1.2.4.zip", 56 "-rw-r--r-- 1 root root 111325 Apr 27 2001 zxJDBC-2.0.1b1.tar.gz", 57 "-rw-r--r-- 1 root root 190144 Apr 27 2001 zxJDBC-2.0.1b1.zip" 58 }; 59 private static final String [] GOODSAMPLES = 60 { 61 "-C--E-----FTP B QUA1I1 18128 41 Aug 12 13:56 QUADTEST", 62 "-C--E-----FTP A QUA1I1 18128 41 Aug 12 13:56 QUADTEST2" 63 }; 64 65 70 public EnterpriseUnixFTPEntryParserTest(String name) 71 { 72 super(name); 73 } 74 75 80 public static TestSuite suite() 81 { 82 83 return (new TestSuite(EnterpriseUnixFTPEntryParserTest.class)); 84 } 85 86 89 public void testParseFieldsOnDirectory() throws Exception 90 { 91 } 93 94 97 public void testParseFieldsOnFile() throws Exception 98 { 99 FTPFile file = getParser().parseFTPEntry("-C--E-----FTP B QUA1I1 18128 5000000000 Aug 12 13:56 QUADTEST"); 100 Calendar today = Calendar.getInstance(); 101 int year = today.get(Calendar.YEAR); 102 103 assertTrue("Should be a file.", 104 file.isFile()); 105 assertEquals("QUADTEST", 106 file.getName()); 107 assertEquals(5000000000L, 108 file.getSize()); 109 assertEquals("QUA1I1", 110 file.getUser()); 111 assertEquals("18128", 112 file.getGroup()); 113 114 if(today.get(Calendar.MONTH) < Calendar.AUGUST) 115 --year; 116 117 Calendar timestamp = file.getTimestamp(); 118 assertEquals(year, timestamp.get(Calendar.YEAR)); 119 assertEquals(Calendar.AUGUST, timestamp.get(Calendar.MONTH)); 120 assertEquals(12, timestamp.get(Calendar.DAY_OF_MONTH)); 121 assertEquals(13, timestamp.get(Calendar.HOUR_OF_DAY)); 122 assertEquals(56, timestamp.get(Calendar.MINUTE)); 123 assertEquals(0, timestamp.get(Calendar.SECOND)); 124 125 checkPermisions(file); 126 } 127 128 131 protected String [] getBadListing() 132 { 133 134 return (BADSAMPLES); 135 } 136 137 140 protected String [] getGoodListing() 141 { 142 143 return (GOODSAMPLES); 144 } 145 146 149 protected FTPFileEntryParser getParser() 150 { 151 152 return (new EnterpriseUnixFTPEntryParser()); 153 } 154 155 161 private void checkPermisions(FTPFile dir) 162 { 163 assertTrue("Owner should not have read permission.", 164 !dir.hasPermission(FTPFile.USER_ACCESS, 165 FTPFile.READ_PERMISSION)); 166 assertTrue("Owner should not have write permission.", 167 !dir.hasPermission(FTPFile.USER_ACCESS, 168 FTPFile.WRITE_PERMISSION)); 169 assertTrue("Owner should not have execute permission.", 170 !dir.hasPermission(FTPFile.USER_ACCESS, 171 FTPFile.EXECUTE_PERMISSION)); 172 assertTrue("Group should not have read permission.", 173 !dir.hasPermission(FTPFile.GROUP_ACCESS, 174 FTPFile.READ_PERMISSION)); 175 assertTrue("Group should not have write permission.", 176 !dir.hasPermission(FTPFile.GROUP_ACCESS, 177 FTPFile.WRITE_PERMISSION)); 178 assertTrue("Group should not have execute permission.", 179 !dir.hasPermission(FTPFile.GROUP_ACCESS, 180 FTPFile.EXECUTE_PERMISSION)); 181 assertTrue("World should not have read permission.", 182 !dir.hasPermission(FTPFile.WORLD_ACCESS, 183 FTPFile.READ_PERMISSION)); 184 assertTrue("World should not have write permission.", 185 !dir.hasPermission(FTPFile.WORLD_ACCESS, 186 FTPFile.WRITE_PERMISSION)); 187 assertTrue("World should not have execute permission.", 188 !dir.hasPermission(FTPFile.WORLD_ACCESS, 189 FTPFile.EXECUTE_PERMISSION)); 190 } 191 } 192 193 200 | Popular Tags |