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