001: /*
002: * Copyright 2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.net.ftp.parser;
017:
018: import org.apache.commons.net.ftp.FTPFile;
019: import org.apache.commons.net.ftp.FTPFileEntryParser;
020:
021: /**
022: * @author <a href="mario@ops.co.at">MarioIvankovits</a>
023: * @version $Id: CompositeFTPParseTestFramework.java 155429 2005-02-26 13:13:04Z dirkv $
024: */
025: public abstract class CompositeFTPParseTestFramework extends
026: FTPParseTestFramework {
027: /**
028: * @see junit.framework.TestCase#TestCase(String)
029: */
030: public CompositeFTPParseTestFramework(String name) {
031: super (name);
032: }
033:
034: /**
035: * @see FTPParseTestFramework#getGoodListing()
036: */
037: protected String[] getGoodListing() {
038: return (getGoodListings()[0]);
039: }
040:
041: /**
042: * Method getBadListing.
043: * Implementors must provide multiple listing that contains failures and
044: * must force the composite parser to switch the FtpEntryParser
045: *
046: * @return String[]
047: */
048: protected abstract String[][] getBadListings();
049:
050: /**
051: * Method getGoodListing.
052: * Implementors must provide multiple listing that passes and
053: * must force the composite parser to switch the FtpEntryParser
054: *
055: * @return String[]
056: */
057: protected abstract String[][] getGoodListings();
058:
059: /**
060: * @see FTPParseTestFramework#getBadListing()
061: */
062: protected String[] getBadListing() {
063: return (getBadListings()[0]);
064: }
065:
066: /* (non-Javadoc)
067: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
068: */
069: public void testConsistentListing() throws Exception {
070: String goodsamples[][] = getGoodListings();
071:
072: for (int i = 0; i < goodsamples.length; i++) {
073: FTPFileEntryParser parser = getParser();
074: for (int j = 0; j < goodsamples[i].length; j++) {
075: String test = goodsamples[i][j];
076: FTPFile f = parser.parseFTPEntry(test);
077: assertNotNull("Failed to parse " + test, f);
078:
079: doAdditionalGoodTests(test, f);
080: }
081: }
082: }
083:
084: /* (non-Javadoc)
085: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
086: */
087: public void testBadListing() throws Exception {
088: String badsamples[][] = getBadListings();
089:
090: for (int i = 0; i < badsamples.length; i++) {
091: FTPFileEntryParser parser = getParser();
092: for (int j = 0; j < badsamples[i].length; j++) {
093: String test = badsamples[i][j];
094: FTPFile f = parser.parseFTPEntry(test);
095: assertNull("Should have Failed to parse " + test, f);
096:
097: doAdditionalBadTests(test, f);
098: }
099: }
100: }
101:
102: // even though all these listings are good using one parser
103: // or the other, this tests that a parser that has succeeded
104: // on one format will fail if another format is substituted.
105: public void testInconsistentListing() throws Exception {
106: String goodsamples[][] = getGoodListings();
107:
108: FTPFileEntryParser parser = getParser();
109:
110: for (int i = 0; i < goodsamples.length; i++) {
111: String test = goodsamples[i][0];
112: FTPFile f = parser.parseFTPEntry(test);
113:
114: switch (i) {
115: case 0:
116: assertNotNull("Failed to parse " + test, f);
117: break;
118: case 1:
119: assertNull("Should have failed to parse " + test, f);
120: break;
121: }
122: }
123: }
124: }
|