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.TestSuite;
019:
020: import org.apache.commons.net.ftp.FTPFile;
021: import org.apache.commons.net.ftp.FTPFileEntryParser;
022:
023: /**
024: * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
025: * @version $Id: OS2FTPEntryParserTest.java 155429 2005-02-26 13:13:04Z dirkv $
026: */
027: public class OS2FTPEntryParserTest extends FTPParseTestFramework {
028:
029: private static final String[] badsamples = {
030: " DIR 12-30-97 12:32 jbrekke",
031: " 0 rsa DIR 11-25-97 09:42 junk",
032: " 0 dir 05-12-97 16:44 LANGUAGE",
033: " 0 DIR 13-05-97 25:49 MPTN",
034: "587823 RSA DIR Jan-08-97 13:58 OS2KRNL",
035: " 33280 A 1997-02-03 13:49 OS2LDR",
036: "12-05-96 05:03PM <DIR> absoft2",
037: "11-14-97 04:21PM 953 AUDITOR3.INI" };
038: private static final String[] goodsamples = {
039: " 0 DIR 12-30-97 12:32 jbrekke",
040: " 0 DIR 11-25-97 09:42 junk",
041: " 0 DIR 05-12-97 16:44 LANGUAGE",
042: " 0 DIR 05-19-97 12:56 local",
043: " 0 DIR 05-12-97 16:52 Maintenance Desktop",
044: " 0 DIR 05-13-97 10:49 MPTN",
045: "587823 RSA DIR 01-08-97 13:58 OS2KRNL",
046: " 33280 A 02-09-97 13:49 OS2LDR",
047: " 0 DIR 11-28-97 09:42 PC",
048: "149473 A 11-17-98 16:07 POPUPLOG.OS2",
049: " 0 DIR 05-12-97 16:44 PSFONTS",
050: " 0 DIR 05-19-2000 12:56 local", };
051:
052: /**
053: * @see junit.framework.TestCase#TestCase(String)
054: */
055: public OS2FTPEntryParserTest(String name) {
056: super (name);
057: }
058:
059: /**
060: * Method suite.
061: * @return TestSuite
062: */
063: public static TestSuite suite() {
064:
065: return (new TestSuite(OS2FTPEntryParserTest.class));
066: }
067:
068: /**
069: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
070: */
071: public void testParseFieldsOnDirectory() throws Exception {
072: FTPFile dir = getParser().parseFTPEntry(
073: " 0 DIR 11-28-97 09:42 PC");
074: assertNotNull("Could not parse entry.", dir);
075: assertTrue("Should have been a directory.", dir.isDirectory());
076: assertEquals(0, dir.getSize());
077: assertEquals("PC", dir.getName());
078: assertEquals("Fri Nov 28 09:42:00 1997", df.format(dir
079: .getTimestamp().getTime()));
080: }
081:
082: /**
083: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
084: */
085: public void testParseFieldsOnFile() throws Exception {
086: FTPFile file = getParser()
087: .parseFTPEntry(
088: "5000000000 A 11-17-98 16:07 POPUPLOG.OS2");
089: assertNotNull("Could not parse entry.", file);
090: assertTrue("Should have been a file.", file.isFile());
091: assertEquals(5000000000L, file.getSize());
092: assertEquals("POPUPLOG.OS2", file.getName());
093: assertEquals("Tue Nov 17 16:07:00 1998", df.format(file
094: .getTimestamp().getTime()));
095: }
096:
097: /**
098: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
099: */
100: protected String[] getBadListing() {
101:
102: return (badsamples);
103: }
104:
105: /**
106: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
107: */
108: protected String[] getGoodListing() {
109:
110: return (goodsamples);
111: }
112:
113: /**
114: * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
115: */
116: protected FTPFileEntryParser getParser() {
117: ConfigurableFTPFileEntryParserImpl parser = new OS2FTPEntryParser();
118: parser.configure(null);
119: return parser;
120: }
121: }
|