1 16 package org.apache.commons.net.ftp.parser; 17 18 import junit.framework.TestSuite; 19 import org.apache.commons.net.ftp.FTPFile; 20 import org.apache.commons.net.ftp.FTPFileEntryParser; 21 22 import java.util.Calendar ; 23 24 27 28 public class OS400FTPEntryParserTest extends CompositeFTPParseTestFramework 29 { 30 private static final String [][] badsamples = 31 { 32 { 33 "PEP 4019 04/03/18 18:58:16 STMF einladung.zip", 34 "PEP 422 03/24 14:06:26 *STMF readme", 35 "PEP 6409 04/03/24 30:06:29 *STMF build.xml", 36 "PEP USR 36864 04/03/24 14:06:34 *DIR dir1/", 37 "PEP 3686404/03/24 14:06:47 *DIR zdir2/" 38 }, 39 40 { 41 "----rwxr-x 1PEP 0 4019 Mar 18 18:58 einladung.zip", 42 "----rwxr-x 1 PEP 0 xx 422 Mar 24 14:06 readme", 43 "----rwxr-x 1 PEP 0 8492 Apr 07 30:13 build.xml", 44 "d---rwxr-x 2 PEP USR 0 45056 Mar 24 14:06 dir1", 45 "d---rwxr-x 2 PEP 0 45056Mar 24 14:06 zdir2" 46 } 47 }; 48 49 private static final String [][] goodsamples = 50 { 51 { 52 "PEP 4019 04/03/18 18:58:16 *STMF einladung.zip", 53 "PEP 422 04/03/24 14:06:26 *STMF readme", 54 "PEP 6409 04/03/24 14:06:29 *STMF build.xml", 55 "PEP 36864 04/03/24 14:06:34 *DIR dir1/", 56 "PEP 36864 04/03/24 14:06:47 *DIR zdir2/" 57 }, 58 { 59 "----rwxr-x 1 PEP 0 4019 Mar 18 18:58 einladung.zip", 60 "----rwxr-x 1 PEP 0 422 Mar 24 14:06 readme", 61 "----rwxr-x 1 PEP 0 8492 Apr 07 07:13 build.xml", 62 "d---rwxr-x 2 PEP 0 45056 Mar 24 14:06 dir1", 63 "d---rwxr-x 2 PEP 0 45056 Mar 24 14:06 zdir2" 64 } 65 }; 66 67 70 public OS400FTPEntryParserTest(String name) 71 { 72 super(name); 73 } 74 75 78 protected String [][] getBadListings() 79 { 80 return badsamples; 81 } 82 83 86 protected String [][] getGoodListings() 87 { 88 return goodsamples; 89 } 90 91 94 protected FTPFileEntryParser getParser() 95 { 96 return new CompositeFileEntryParser(new FTPFileEntryParser[] 97 { 98 new OS400FTPEntryParser(), 99 new UnixFTPEntryParser() 100 }); 101 } 102 103 106 public void testParseFieldsOnDirectory() throws Exception 107 { 108 FTPFile f = getParser().parseFTPEntry("PEP 36864 04/03/24 14:06:34 *DIR dir1/"); 109 assertNotNull("Could not parse entry.", 110 f); 111 assertTrue("Should have been a directory.", 112 f.isDirectory()); 113 assertEquals("PEP", 114 f.getUser()); 115 assertEquals("dir1", 116 f.getName()); 117 assertEquals(36864, 118 f.getSize()); 119 120 Calendar cal = Calendar.getInstance(); 121 cal.set(Calendar.MONTH, Calendar.MARCH); 122 123 cal.set(Calendar.YEAR, 2004); 124 cal.set(Calendar.DATE, 24); 125 cal.set(Calendar.HOUR_OF_DAY, 14); 126 cal.set(Calendar.MINUTE, 6); 127 cal.set(Calendar.SECOND, 34); 128 129 assertEquals(df.format(cal.getTime()), 130 df.format(f.getTimestamp().getTime())); 131 } 132 133 protected void doAdditionalGoodTests(String test, FTPFile f) 134 { 135 if (test.startsWith("d")) 136 { 137 assertEquals("directory.type", 138 FTPFile.DIRECTORY_TYPE, f.getType()); 139 } 140 } 141 142 145 public void testParseFieldsOnFile() throws Exception 146 { 147 FTPFile f = getParser().parseFTPEntry("PEP 5000000000 04/03/24 14:06:29 *STMF build.xml"); 148 assertNotNull("Could not parse entry.", 149 f); 150 assertTrue("Should have been a file.", 151 f.isFile()); 152 assertEquals("PEP", 153 f.getUser()); 154 assertEquals("build.xml", 155 f.getName()); 156 assertEquals(5000000000L, 157 f.getSize()); 158 159 Calendar cal = Calendar.getInstance(); 160 161 cal.set(Calendar.DATE, 24); 162 cal.set(Calendar.MONTH, Calendar.MARCH); 163 cal.set(Calendar.YEAR, 2004); 164 cal.set(Calendar.HOUR_OF_DAY, 14); 165 cal.set(Calendar.MINUTE, 6); 166 cal.set(Calendar.SECOND, 29); 167 assertEquals(df.format(cal.getTime()), 168 df.format(f.getTimestamp().getTime())); 169 } 170 171 176 public static TestSuite suite() 177 { 178 return(new TestSuite(OS400FTPEntryParserTest.class)); 179 } 180 } 181 | Popular Tags |