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