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 org.apache.commons.net.ftp.FTPFile;
20 import org.apache.commons.net.ftp.FTPFileEntryParser;
21
22
23
24 public abstract class CompositeFTPParseTestFramework extends AbstractFTPParseTest {
25 public CompositeFTPParseTestFramework(final String name) {
26 super(name);
27 }
28
29 @Override
30 protected String[] getBadListing() {
31 return getBadListings()[0];
32 }
33
34
35
36
37
38
39 protected abstract String[][] getBadListings();
40
41 @Override
42 protected String[] getGoodListing() {
43 return getGoodListings()[0];
44 }
45
46
47
48
49
50
51 protected abstract String[][] getGoodListings();
52
53
54
55
56
57
58 @Override
59 public void testBadListing() {
60 final String badsamples[][] = getBadListings();
61
62 for (final String[] badsample : badsamples) {
63 final FTPFileEntryParser parser = getParser();
64 for (final String test : badsample) {
65 final FTPFile f = parser.parseFTPEntry(test);
66 assertNull("Should have Failed to parse " + test, nullFileOrNullDate(f));
67
68 doAdditionalBadTests(test, f);
69 }
70 }
71 }
72
73
74
75
76
77
78 public void testConsistentListing() {
79 final String goodsamples[][] = getGoodListings();
80
81 for (final String[] goodsample : goodsamples) {
82 final FTPFileEntryParser parser = getParser();
83 for (final String test : goodsample) {
84 final FTPFile f = parser.parseFTPEntry(test);
85 assertNotNull("Failed to parse " + test, f);
86
87 doAdditionalGoodTests(test, f);
88 }
89 }
90 }
91
92
93
94
95 public void testInconsistentListing() {
96 final String goodsamples[][] = getGoodListings();
97
98 final FTPFileEntryParser parser = getParser();
99
100 for (int i = 0; i < goodsamples.length; i++) {
101 final String test = goodsamples[i][0];
102 final FTPFile f = parser.parseFTPEntry(test);
103
104 switch (i) {
105 case 0:
106 assertNotNull("Failed to parse " + test, f);
107 break;
108 case 1:
109 assertNull("Should have failed to parse " + test, f);
110 break;
111 }
112 }
113 }
114 }