1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.net.ftp.parser;
18
19 import java.util.Calendar;
20
21 import junit.framework.TestSuite;
22
23 import org.apache.commons.net.ftp.FTPFile;
24 import org.apache.commons.net.ftp.FTPFileEntryParser;
25
26
27
28
29
30 public class NetwareFTPEntryParserTest extends FTPParseTestFramework {
31
32 private static final String[] badsamples = {
33 "a [-----F--] SCION_SYS 512 Apr 13 23:52 SYS",
34 "d [----AF--] 0 512 10-04-2001 _ADMIN"
35 };
36
37 private static final String [] goodsamples = {
38 "d [-----F--] SCION_SYS 512 Apr 13 23:52 SYS",
39 "d [----AF--] 0 512 Feb 22 17:32 _ADMIN",
40 "d [-W---F--] SCION_VOL2 512 Apr 13 23:12 VOL2",
41 "- [RWCEAFMS] rwinston 19968 Mar 12 15:20 Executive Summary.doc",
42 "d [RWCEAFMS] rwinston 512 Nov 24 2005 Favorites"
43 };
44
45
46
47
48 public NetwareFTPEntryParserTest(String name) {
49 super(name);
50 }
51
52
53
54
55 @Override
56 protected String[] getBadListing() {
57 return (badsamples);
58 }
59
60
61
62
63 @Override
64 protected String[] getGoodListing() {
65 return (goodsamples);
66 }
67
68
69
70
71 @Override
72 protected FTPFileEntryParser getParser() {
73 return (new NetwareFTPEntryParser());
74 }
75
76
77
78
79 @Override
80 public void testParseFieldsOnDirectory() throws Exception {
81 String reply = "d [-W---F--] testUser 512 Apr 13 23:12 testFile";
82 FTPFile f = getParser().parseFTPEntry(reply);
83
84 assertNotNull("Could not parse file", f);
85 assertEquals("testFile", f.getName());
86 assertEquals(512L, f.getSize());
87 assertEquals("testUser", f.getUser());
88 assertTrue("Directory flag is not set!", f.isDirectory());
89
90 Calendar cal = Calendar.getInstance();
91 cal.set(Calendar.MONTH, 3);
92 cal.set(Calendar.DAY_OF_MONTH, 13);
93 cal.set(Calendar.HOUR_OF_DAY, 23);
94 cal.set(Calendar.MINUTE, 12);
95 cal.set(Calendar.SECOND, 0);
96 cal.set(Calendar.MILLISECOND, 0);
97 cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR));
98
99 assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp()
100 .getTime()));
101
102 }
103
104
105
106
107
108 @Override
109 public void testParseFieldsOnFile() throws Exception {
110 String reply = "- [R-CEAFMS] rwinston 19968 Mar 12 15:20 Document name with spaces.doc";
111
112 FTPFile f = getParser().parseFTPEntry(reply);
113
114 assertNotNull("Could not parse file", f);
115 assertEquals("Document name with spaces.doc", f.getName());
116 assertEquals(19968L, f.getSize());
117 assertEquals("rwinston", f.getUser());
118 assertTrue("File flag is not set!", f.isFile());
119
120 assertTrue(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
121 assertFalse(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
122 }
123
124
125
126
127
128
129 public static TestSuite suite() {
130 return (new TestSuite(NetwareFTPEntryParserTest.class));
131 }
132
133
134 }