1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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 * @author <a href="mario@ops.co.at">MarioIvankovits</a>
24 * @version $Id: CompositeFTPParseTestFramework.java 155429 2005-02-26 13:13:04Z dirkv $
25 */
26 public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
27 {
28 /**
29 * @see junit.framework.TestCase#TestCase(String)
30 */
31 public CompositeFTPParseTestFramework(String name)
32 {
33 super(name);
34 }
35
36 /**
37 * @see FTPParseTestFramework#getGoodListing()
38 */
39 @Override
40 protected String[] getGoodListing()
41 {
42 return (getGoodListings()[0]);
43 }
44
45 /**
46 * Method getBadListing.
47 * Implementors must provide multiple listing that contains failures and
48 * must force the composite parser to switch the FtpEntryParser
49 *
50 * @return String[]
51 */
52 protected abstract String[][] getBadListings();
53
54 /**
55 * Method getGoodListing.
56 * Implementors must provide multiple listing that passes and
57 * must force the composite parser to switch the FtpEntryParser
58 *
59 * @return String[]
60 */
61 protected abstract String[][] getGoodListings();
62
63 /**
64 * @see FTPParseTestFramework#getBadListing()
65 */
66 @Override
67 protected String[] getBadListing()
68 {
69 return (getBadListings()[0]);
70 }
71
72 /* (non-Javadoc)
73 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
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 /* (non-Javadoc)
95 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
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 // even though all these listings are good using one parser
118 // or the other, this tests that a parser that has succeeded
119 // on one format will fail if another format is substituted.
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 }