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 import junit.framework.TestCase;
19
20 import java.text.SimpleDateFormat;
21 import java.util.Locale;
22 import org.apache.commons.net.ftp.FTPFile;
23 import org.apache.commons.net.ftp.FTPFileEntryParser;
24
25
26
27
28
29 public abstract class FTPParseTestFramework extends TestCase
30 {
31 private FTPFileEntryParser parser = null;
32 protected SimpleDateFormat df = null;
33
34
35
36
37 public FTPParseTestFramework(String name)
38 {
39 super(name);
40 }
41
42
43
44
45
46
47 public void testBadListing() throws Exception
48 {
49
50 String[] badsamples = getBadListing();
51 for (int i = 0; i < badsamples.length; i++)
52 {
53
54 String test = badsamples[i];
55 FTPFile f = parser.parseFTPEntry(test);
56 assertNull("Should have Failed to parse " + test,
57 nullFileOrNullDate(f));
58
59 doAdditionalBadTests(test, f);
60 }
61 }
62
63
64
65
66
67
68 public void testGoodListing() throws Exception
69 {
70
71 String[] goodsamples = getGoodListing();
72 for (int i = 0; i < goodsamples.length; i++)
73 {
74
75 String test = goodsamples[i];
76 FTPFile f = parser.parseFTPEntry(test);
77 assertNotNull("Failed to parse " + test,
78 f);
79
80 doAdditionalGoodTests(test, f);
81 }
82 }
83
84
85
86
87
88
89
90 protected void doAdditionalGoodTests(String test, FTPFile f)
91 {
92 }
93
94
95
96
97
98
99
100 protected void doAdditionalBadTests(String test, FTPFile f)
101 {
102 }
103
104
105
106
107
108
109 protected abstract String[] getBadListing();
110
111
112
113
114
115
116 protected abstract String[] getGoodListing();
117
118
119
120
121
122
123 protected abstract FTPFileEntryParser getParser();
124
125
126
127
128
129
130 public abstract void testParseFieldsOnDirectory() throws Exception;
131
132
133
134
135
136
137 public abstract void testParseFieldsOnFile() throws Exception;
138
139
140
141
142 @Override
143 protected void setUp() throws Exception
144 {
145 super.setUp();
146 parser = getParser();
147 df = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
148 }
149
150
151
152
153
154
155
156 protected FTPFile nullFileOrNullDate(FTPFile f) {
157 if (f==null){
158 return null;
159 }
160 if (f.getTimestamp() == null){
161 return null;
162 }
163 return f;
164 }
165 }