1 16 package org.apache.commons.net.ftp.parser; 17 18 import java.text.SimpleDateFormat ; 19 import java.util.Calendar ; 20 import java.util.Date ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.commons.net.ftp.FTPClientConfig; 25 import org.apache.commons.net.ftp.FTPFile; 26 27 36 public class FTPConfigEntryParserTest extends TestCase { 37 38 private SimpleDateFormat df = new SimpleDateFormat (); 39 40 public void testParseFieldsOnAIX() { 41 42 FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX); 44 config.setDefaultDateFormatStr("dd MMM HH:mm"); 45 46 UnixFTPEntryParser parser = new UnixFTPEntryParser(); 47 parser.configure(config); 48 49 FTPFile f = parser.parseFTPEntry("-rw-r----- 1 ravensm sca 814 02 Mar 16:27 ZMIR2.m"); 50 51 assertNotNull("Could not parse entry.", f); 52 assertFalse("Is not a directory.", f.isDirectory()); 53 54 assertTrue("Should have user read permission.", f.hasPermission( 55 FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); 56 assertTrue("Should have user write permission.", f.hasPermission( 57 FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); 58 assertFalse("Should NOT have user execute permission.", f 59 .hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); 60 assertTrue("Should have group read permission.", f.hasPermission( 61 FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); 62 assertFalse("Should NOT have group write permission.", f 63 .hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); 64 assertFalse("Should NOT have group execute permission.", 65 f.hasPermission(FTPFile.GROUP_ACCESS, 66 FTPFile.EXECUTE_PERMISSION)); 67 assertFalse("Should NOT have world read permission.", f.hasPermission( 68 FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); 69 assertFalse("Should NOT have world write permission.", f 70 .hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); 71 assertFalse("Should NOT have world execute permission.", 72 f.hasPermission(FTPFile.WORLD_ACCESS, 73 FTPFile.EXECUTE_PERMISSION)); 74 75 assertEquals(1, f.getHardLinkCount()); 76 77 assertEquals("ravensm", f.getUser()); 78 assertEquals("sca", f.getGroup()); 79 80 assertEquals("ZMIR2.m", f.getName()); 81 assertEquals(814, f.getSize()); 82 83 Calendar cal = Calendar.getInstance(); 84 85 Date refDate = new Date (); 86 87 cal.set(Calendar.MONTH, Calendar.MARCH); 88 cal.set(Calendar.DATE, 2); 89 cal.set(Calendar.HOUR_OF_DAY, 16); 90 cal.set(Calendar.MINUTE, 27); 91 cal.set(Calendar.SECOND, 0); 92 93 cal.set(Calendar.YEAR, 1970); 96 97 assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp() 98 .getTime())); 99 } 100 101 106 public void testParseEntryWithSymlink() { 107 108 FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX); 109 config.setDefaultDateFormatStr("yyyy-MM-dd HH:mm"); 110 111 UnixFTPEntryParser parser = new UnixFTPEntryParser(); 112 parser.configure(config); 113 114 FTPFile f = parser.parseFTPEntry("lrwxrwxrwx 1 neeme neeme 23 2005-03-02 18:06 macros"); 115 116 assertNotNull("Could not parse entry.", f); 117 assertFalse("Is not a directory.", f.isDirectory()); 118 assertTrue("Is a symbolic link", f.isSymbolicLink()); 119 120 assertTrue("Should have user read permission.", f.hasPermission( 121 FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); 122 assertTrue("Should have user write permission.", f.hasPermission( 123 FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); 124 assertTrue("Should have user execute permission.", f 125 .hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); 126 assertTrue("Should have group read permission.", f.hasPermission( 127 FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); 128 assertTrue("Should have group write permission.", f 129 .hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); 130 assertTrue("Should have group execute permission.", 131 f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); 132 assertTrue("Should have world read permission.", f.hasPermission( 133 FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); 134 assertTrue("Should have world write permission.", f 135 .hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); 136 assertTrue("Should have world execute permission.", 137 f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); 138 139 assertEquals(1, f.getHardLinkCount()); 140 141 assertEquals("neeme", f.getUser()); 142 assertEquals("neeme", f.getGroup()); 143 144 assertEquals("macros", f.getName()); 145 assertEquals(23, f.getSize()); 146 147 Calendar cal = Calendar.getInstance(); 148 149 Date refDate = new Date (); 150 151 cal.set(Calendar.MONTH, Calendar.MARCH); 152 cal.set(Calendar.DATE, 2); 153 cal.set(Calendar.HOUR_OF_DAY, 18); 154 cal.set(Calendar.MINUTE, 06); 155 cal.set(Calendar.SECOND, 0); 156 cal.set(Calendar.YEAR, 2005); 157 158 assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp() 159 .getTime())); 160 161 } 162 163 } 164 | Popular Tags |