001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.net.ftp.parser;
018
019 import org.apache.commons.net.ftp.FTPFile;
020 import org.apache.commons.net.ftp.FTPFileEntryParser;
021
022 /**
023 * @author <a href="mario@ops.co.at">MarioIvankovits</a>
024 * @version $Id: CompositeFTPParseTestFramework.java 155429 2005-02-26 13:13:04Z dirkv $
025 */
026 public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
027 {
028 /**
029 * @see junit.framework.TestCase#TestCase(String)
030 */
031 public CompositeFTPParseTestFramework(String name)
032 {
033 super(name);
034 }
035
036 /**
037 * @see FTPParseTestFramework#getGoodListing()
038 */
039 @Override
040 protected String[] getGoodListing()
041 {
042 return (getGoodListings()[0]);
043 }
044
045 /**
046 * Method getBadListing.
047 * Implementors must provide multiple listing that contains failures and
048 * must force the composite parser to switch the FtpEntryParser
049 *
050 * @return String[]
051 */
052 protected abstract String[][] getBadListings();
053
054 /**
055 * Method getGoodListing.
056 * Implementors must provide multiple listing that passes and
057 * must force the composite parser to switch the FtpEntryParser
058 *
059 * @return String[]
060 */
061 protected abstract String[][] getGoodListings();
062
063 /**
064 * @see FTPParseTestFramework#getBadListing()
065 */
066 @Override
067 protected String[] getBadListing()
068 {
069 return (getBadListings()[0]);
070 }
071
072 /* (non-Javadoc)
073 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
074 */
075 public void testConsistentListing() throws Exception
076 {
077 String goodsamples[][] = getGoodListings();
078
079 for (int i = 0; i < goodsamples.length; i++)
080 {
081 FTPFileEntryParser parser = getParser();
082 for (int j = 0; j < goodsamples[i].length; j++)
083 {
084 String test = goodsamples[i][j];
085 FTPFile f = parser.parseFTPEntry(test);
086 assertNotNull("Failed to parse " + test,
087 f);
088
089 doAdditionalGoodTests(test, f);
090 }
091 }
092 }
093
094 /* (non-Javadoc)
095 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
096 */
097 @Override
098 public void testBadListing() throws Exception
099 {
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 }