001: /*
002: * Copyright 2001-2005 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 junit.framework.TestCase;
019:
020: import java.text.SimpleDateFormat;
021: import java.util.Locale;
022: import org.apache.commons.net.ftp.FTPFile;
023: import org.apache.commons.net.ftp.FTPFileEntryParser;
024:
025: /**
026: * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
027: * @version $Id: FTPParseTestFramework.java 165675 2005-05-02 20:09:55Z rwinston $
028: */
029: public abstract class FTPParseTestFramework extends TestCase {
030: private FTPFileEntryParser parser = null;
031: protected SimpleDateFormat df = null;
032:
033: /**
034: * @see junit.framework.TestCase#TestCase(String)
035: */
036: public FTPParseTestFramework(String name) {
037: super (name);
038: }
039:
040: /**
041: * Method testBadListing.
042: * Tests that parser provided failures actually fail.
043: * @throws Exception
044: */
045: public void testBadListing() throws Exception {
046:
047: String[] badsamples = getBadListing();
048: for (int i = 0; i < badsamples.length; i++) {
049:
050: String test = badsamples[i];
051: FTPFile f = parser.parseFTPEntry(test);
052: assertNull("Should have Failed to parse " + test, f);
053:
054: doAdditionalBadTests(test, f);
055: }
056: }
057:
058: /**
059: * Method testGoodListing.
060: * Test that parser provided listings pass.
061: * @throws Exception
062: */
063: public void testGoodListing() throws Exception {
064:
065: String[] goodsamples = getGoodListing();
066: for (int i = 0; i < goodsamples.length; i++) {
067:
068: String test = goodsamples[i];
069: FTPFile f = parser.parseFTPEntry(test);
070: assertNotNull("Failed to parse " + test, f);
071:
072: doAdditionalGoodTests(test, f);
073: }
074: }
075:
076: /**
077: * during processing you could hook here to do additional tests
078: *
079: * @param test raw entry
080: * @param f parsed entry
081: */
082: protected void doAdditionalGoodTests(String test, FTPFile f) {
083: }
084:
085: /**
086: * during processing you could hook here to do additional tests
087: *
088: * @param test raw entry
089: * @param f parsed entry
090: */
091: protected void doAdditionalBadTests(String test, FTPFile f) {
092: }
093:
094: /**
095: * Method getBadListing.
096: * Implementors must provide a listing that contains failures.
097: * @return String[]
098: */
099: protected abstract String[] getBadListing();
100:
101: /**
102: * Method getGoodListing.
103: * Implementors must provide a listing that passes.
104: * @return String[]
105: */
106: protected abstract String[] getGoodListing();
107:
108: /**
109: * Method getParser.
110: * Provide the parser to use for testing.
111: * @return FTPFileEntryParser
112: */
113: protected abstract FTPFileEntryParser getParser();
114:
115: /**
116: * Method testParseFieldsOnDirectory.
117: * Provide a test to show that fields on a directory entry are parsed correctly.
118: * @throws Exception
119: */
120: public abstract void testParseFieldsOnDirectory() throws Exception;
121:
122: /**
123: * Method testParseFieldsOnFile.
124: * Provide a test to show that fields on a file entry are parsed correctly.
125: * @throws Exception
126: */
127: public abstract void testParseFieldsOnFile() throws Exception;
128:
129: /**
130: * @see junit.framework.TestCase#setUp()
131: */
132: protected void setUp() throws Exception {
133: super .setUp();
134: parser = getParser();
135: df = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
136: }
137: }
|