UnixFTPEntryParserTestpublic class UnixFTPEntryParserTest extends FTPParseTestFramework
Fields Summary |
---|
private static final String[] | badsamples | private static final String[] | goodsamples |
Constructors Summary |
---|
public UnixFTPEntryParserTest(String name)
super(name);
|
Methods Summary |
---|
private void | checkPermissions(org.apache.commons.net.ftp.FTPFile f)Method checkPermissions.
Verify that the persmissions were properly set.
assertTrue("Should have user read permission.", f.hasPermission(
FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
assertTrue("Should have user write permission.", f.hasPermission(
FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
assertTrue("Should have user execute permission.", f.hasPermission(
FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
assertTrue("Should have group read permission.", f.hasPermission(
FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
assertTrue("Should NOT have group write permission.", !f.hasPermission(
FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
assertTrue("Should have group execute permission.", f.hasPermission(
FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
assertTrue("Should have world read permission.", f.hasPermission(
FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
assertTrue("Should NOT have world write permission.", !f.hasPermission(
FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
assertTrue("Should have world execute permission.", f.hasPermission(
FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
| protected void | doAdditionalGoodTests(java.lang.String test, org.apache.commons.net.ftp.FTPFile f)
String link = f.getLink();
if (null != link) {
int linklen = link.length();
if (linklen > 0) {
assertEquals(link, test.substring(test.length() - linklen));
assertEquals(f.getType(), FTPFile.SYMBOLIC_LINK_TYPE);
}
}
int type = f.getType();
switch (test.charAt(0))
{
case 'd":
assertEquals("Type of "+ test, type, FTPFile.DIRECTORY_TYPE);
break;
case 'l":
assertEquals("Type of "+ test, type, FTPFile.SYMBOLIC_LINK_TYPE);
break;
case 'b":
case 'c":
assertEquals(0, f.getHardLinkCount());
case 'f":
case '-":
assertEquals("Type of "+ test, type, FTPFile.FILE_TYPE);
break;
default:
assertEquals("Type of "+ test, type, FTPFile.UNKNOWN_TYPE);
}
for (int access = FTPFile.USER_ACCESS;
access <= FTPFile.WORLD_ACCESS; access++)
{
for (int perm = FTPFile.READ_PERMISSION;
perm <= FTPFile.EXECUTE_PERMISSION; perm++)
{
int pos = 3*access + perm + 1;
char permchar = test.charAt(pos);
assertEquals("Permission " + test.substring(1,10),
f.hasPermission(access, perm),
permchar != '-" && !Character.isUpperCase(permchar));
}
}
| protected java.lang.String[] | getBadListing()
return (badsamples);
| protected java.lang.String[] | getGoodListing()
return (goodsamples);
| protected org.apache.commons.net.ftp.FTPFileEntryParser | getParser()
return (new UnixFTPEntryParser());
| public static junit.framework.TestSuite | suite()Method suite.
return (new TestSuite(UnixFTPEntryParserTest.class));
| public void | testNumericDateFormat()
String testNumericDF =
"-rw-r----- 1 neeme neeme 346 2005-04-08 11:22 services.vsp";
String testNumericDF2 =
"lrwxrwxrwx 1 neeme neeme 23 2005-03-02 18:06 macros -> ./../../global/macros/.";
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());
FTPFile f2 = parser.parseFTPEntry(testNumericDF2);
assertNotNull("Failed to parse " + testNumericDF2,
f2);
assertEquals("symbolic link", "./../../global/macros/.", f2.getLink());
| public void | testParseFieldsOnDirectory()
FTPFile f = getParser().parseFTPEntry("drwxr-xr-x 2 user group 4096 Mar 2 15:13 zxbox");
assertNotNull("Could not parse entry.", f);
assertTrue("Should have been a directory.", f.isDirectory());
checkPermissions(f);
assertEquals(2, f.getHardLinkCount());
assertEquals("user", f.getUser());
assertEquals("group", f.getGroup());
assertEquals("zxbox", f.getName());
assertEquals(4096, f.getSize());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
if (f.getTimestamp().getTime().before(cal.getTime())) {
cal.add(Calendar.YEAR, -1);
}
cal.set(Calendar.DATE, 2);
cal.set(Calendar.HOUR_OF_DAY, 15);
cal.set(Calendar.MINUTE, 13);
assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp()
.getTime()));
| public void | testParseFieldsOnFile()
FTPFile f = getParser()
.parseFTPEntry(
"-rwxr-xr-x 2 user group 5000000000 Mar 2 15:13 zxbox");
assertNotNull("Could not parse entry.", f);
assertTrue("Should have been a file.", f.isFile());
checkPermissions(f);
assertEquals(2, f.getHardLinkCount());
assertEquals("user", f.getUser());
assertEquals("group", f.getGroup());
assertEquals("zxbox", f.getName());
assertEquals(5000000000L, f.getSize());
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
if (f.getTimestamp().getTime().before(cal.getTime())) {
cal.add(Calendar.YEAR, -1);
}
cal.set(Calendar.DATE, 2);
cal.set(Calendar.HOUR_OF_DAY, 15);
cal.set(Calendar.MINUTE, 13);
assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
|
|