KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > net > ftp > parser > CompositeFTPParseTestFramework


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 JavaDoc name)
31     {
32         super(name);
33     }
34
35     /**
36      * @see FTPParseTestFramework#getGoodListing()
37      */

38     protected String JavaDoc[] 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 JavaDoc[][] 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 JavaDoc[][] getGoodListings();
60
61     /**
62      * @see FTPParseTestFramework#getBadListing()
63      */

64     protected String JavaDoc[] getBadListing()
65     {
66         return (getBadListings()[0]);
67     }
68
69     /* (non-Javadoc)
70      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
71      */

72     public void testConsistentListing() throws Exception JavaDoc
73     {
74         String JavaDoc 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 JavaDoc 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     /* (non-Javadoc)
92      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
93      */

94     public void testBadListing() throws Exception JavaDoc
95     {
96         String JavaDoc 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 JavaDoc 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     // even though all these listings are good using one parser
114
// or the other, this tests that a parser that has succeeded
115
// on one format will fail if another format is substituted.
116
public void testInconsistentListing() throws Exception JavaDoc
117     {
118         String JavaDoc goodsamples[][] = getGoodListings();
119
120         FTPFileEntryParser parser = getParser();
121
122         for (int i = 0; i < goodsamples.length; i++)
123         {
124             String JavaDoc 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 }
139
Popular Tags