1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.net.ftp.parser;
17
18 import org.apache.commons.net.ftp.FTPFile;
19 import org.apache.commons.net.ftp.FTPFileEntryParser;
20
21 /**
22 * @author <a href="mario@ops.co.at">MarioIvankovits</a>
23 * @version $Id: CompositeFTPParseTestFramework.java 155429 2005-02-26 13:13:04Z dirkv $
24 */
25 public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
26 {
27 /**
28 * @see junit.framework.TestCase#TestCase(String)
29 */
30 public CompositeFTPParseTestFramework(String name)
31 {
32 super(name);
33 }
34
35 /**
36 * @see FTPParseTestFramework#getGoodListing()
37 */
38 protected String[] getGoodListing()
39 {
40 return (getGoodListings()[0]);
41 }
42
43 /**
44 * Method getBadListing.
45 * Implementors must provide multiple listing that contains failures and
46 * must force the composite parser to switch the FtpEntryParser
47 *
48 * @return String[]
49 */
50 protected abstract String[][] getBadListings();
51
52 /**
53 * Method getGoodListing.
54 * Implementors must provide multiple listing that passes and
55 * must force the composite parser to switch the FtpEntryParser
56 *
57 * @return String[]
58 */
59 protected abstract String[][] getGoodListings();
60
61 /**
62 * @see FTPParseTestFramework#getBadListing()
63 */
64 protected String[] getBadListing()
65 {
66 return (getBadListings()[0]);
67 }
68
69
70
71
72 public void testConsistentListing() throws Exception
73 {
74 String goodsamples[][] = getGoodListings();
75
76 for (int i = 0; i < goodsamples.length; i++)
77 {
78 FTPFileEntryParser parser = getParser();
79 for (int j = 0; j < goodsamples[i].length; j++)
80 {
81 String test = goodsamples[i][j];
82 FTPFile f = parser.parseFTPEntry(test);
83 assertNotNull("Failed to parse " + test,
84 f);
85
86 doAdditionalGoodTests(test, f);
87 }
88 }
89 }
90
91
92
93
94 public void testBadListing() throws Exception
95 {
96 String badsamples[][] = getBadListings();
97
98 for (int i = 0; i < badsamples.length; i++)
99 {
100 FTPFileEntryParser parser = getParser();
101 for (int j = 0; j < badsamples[i].length; j++)
102 {
103 String test = badsamples[i][j];
104 FTPFile f = parser.parseFTPEntry(test);
105 assertNull("Should have Failed to parse " + test,
106 f);
107
108 doAdditionalBadTests(test, f);
109 }
110 }
111 }
112
113
114
115
116 public void testInconsistentListing() throws Exception
117 {
118 String goodsamples[][] = getGoodListings();
119
120 FTPFileEntryParser parser = getParser();
121
122 for (int i = 0; i < goodsamples.length; i++)
123 {
124 String test = goodsamples[i][0];
125 FTPFile f = parser.parseFTPEntry(test);
126
127 switch (i)
128 {
129 case 0:
130 assertNotNull("Failed to parse " + test, f);
131 break;
132 case 1:
133 assertNull("Should have failed to parse " + test, f);
134 break;
135 }
136 }
137 }
138 }