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
25
26 public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
27 {
28
29
30
31 public CompositeFTPParseTestFramework(String name)
32 {
33 super(name);
34 }
35
36
37
38
39 @Override
40 protected String[] getGoodListing()
41 {
42 return (getGoodListings()[0]);
43 }
44
45
46
47
48
49
50
51
52 protected abstract String[][] getBadListings();
53
54
55
56
57
58
59
60
61 protected abstract String[][] getGoodListings();
62
63
64
65
66 @Override
67 protected String[] getBadListing()
68 {
69 return (getBadListings()[0]);
70 }
71
72
73
74
75 public void testConsistentListing() throws Exception
76 {
77 String goodsamples[][] = getGoodListings();
78
79 for (int i = 0; i < goodsamples.length; i++)
80 {
81 FTPFileEntryParser parser = getParser();
82 for (int j = 0; j < goodsamples[i].length; j++)
83 {
84 String test = goodsamples[i][j];
85 FTPFile f = parser.parseFTPEntry(test);
86 assertNotNull("Failed to parse " + test,
87 f);
88
89 doAdditionalGoodTests(test, f);
90 }
91 }
92 }
93
94
95
96
97 @Override
98 public void testBadListing() throws Exception
99 {
100 String badsamples[][] = getBadListings();
101
102 for (int i = 0; i < badsamples.length; i++)
103 {
104 FTPFileEntryParser parser = getParser();
105 for (int j = 0; j < badsamples[i].length; j++)
106 {
107 String test = badsamples[i][j];
108 FTPFile f = parser.parseFTPEntry(test);
109 assertNull("Should have Failed to parse " + test,
110 nullFileOrNullDate(f));
111
112 doAdditionalBadTests(test, f);
113 }
114 }
115 }
116
117
118
119
120 public void testInconsistentListing() throws Exception
121 {
122 String goodsamples[][] = getGoodListings();
123
124 FTPFileEntryParser parser = getParser();
125
126 for (int i = 0; i < goodsamples.length; i++)
127 {
128 String test = goodsamples[i][0];
129 FTPFile f = parser.parseFTPEntry(test);
130
131 switch (i)
132 {
133 case 0:
134 assertNotNull("Failed to parse " + test, f);
135 break;
136 case 1:
137 assertNull("Should have failed to parse " + test, f);
138 break;
139 }
140 }
141 }
142 }