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 import org.apache.commons.net.ftp.FTPFile;
021 import org.apache.commons.net.ftp.FTPFileEntryParser;
022
023 import java.util.Calendar;
024
025 /**
026 * @version $Id: OS400FTPEntryParserTest.java 155429 2005-02-26 13:13:04Z dirkv $
027 */
028
029 public class OS400FTPEntryParserTest extends CompositeFTPParseTestFramework
030 {
031 private static final String[][] badsamples =
032 {
033 {
034 "PEP 4019 04/03/18 18:58:16 STMF einladung.zip",
035 "PEP 422 03/24 14:06:26 *STMF readme",
036 "PEP 6409 04/03/24 30:06:29 *STMF build.xml",
037 "PEP USR 36864 04/03/24 14:06:34 *DIR dir1/",
038 "PEP 3686404/03/24 14:06:47 *DIR zdir2/"
039 },
040
041 {
042 "----rwxr-x 1PEP 0 4019 Mar 18 18:58 einladung.zip",
043 "----rwxr-x 1 PEP 0 xx 422 Mar 24 14:06 readme",
044 "----rwxr-x 1 PEP 0 8492 Apr 07 30:13 build.xml",
045 "d---rwxr-x 2 PEP USR 0 45056 Mar 24 14:06 dir1",
046 "d---rwxr-x 2 PEP 0 45056Mar 24 14:06 zdir2"
047 }
048 };
049
050 private static final String[][] goodsamples =
051 {
052 {
053 "PEP 4019 04/03/18 18:58:16 *STMF einladung.zip",
054 "PEP 422 04/03/24 14:06:26 *STMF readme",
055 "PEP 6409 04/03/24 14:06:29 *STMF build.xml",
056 "PEP 36864 04/03/24 14:06:34 *DIR dir1/",
057 "PEP 36864 04/03/24 14:06:47 *DIR zdir2/"
058 },
059 {
060 "----rwxr-x 1 PEP 0 4019 Mar 18 18:58 einladung.zip",
061 "----rwxr-x 1 PEP 0 422 Mar 24 14:06 readme",
062 "----rwxr-x 1 PEP 0 8492 Apr 07 07:13 build.xml",
063 "d---rwxr-x 2 PEP 0 45056 Mar 24 14:06 dir1",
064 "d---rwxr-x 2 PEP 0 45056 Mar 24 14:06 zdir2"
065 }
066 };
067
068 /**
069 * @see junit.framework.TestCase#TestCase(String)
070 */
071 public OS400FTPEntryParserTest(String name)
072 {
073 super(name);
074 }
075
076 /**
077 * @see FTPParseTestFramework#getBadListing()
078 */
079 @Override
080 protected String[][] getBadListings()
081 {
082 return badsamples;
083 }
084
085 /**
086 * @see FTPParseTestFramework#getGoodListing()
087 */
088 @Override
089 protected String[][] getGoodListings()
090 {
091 return goodsamples;
092 }
093
094 /**
095 * @see FTPParseTestFramework#getParser()
096 */
097 @Override
098 protected FTPFileEntryParser getParser()
099 {
100 return new CompositeFileEntryParser(new FTPFileEntryParser[]
101 {
102 new OS400FTPEntryParser(),
103 new UnixFTPEntryParser()
104 });
105 }
106
107 /**
108 * @see FTPParseTestFramework#testParseFieldsOnDirectory()
109 */
110 @Override
111 public void testParseFieldsOnDirectory() throws Exception
112 {
113 FTPFile f = getParser().parseFTPEntry("PEP 36864 04/03/24 14:06:34 *DIR dir1/");
114 assertNotNull("Could not parse entry.",
115 f);
116 assertTrue("Should have been a directory.",
117 f.isDirectory());
118 assertEquals("PEP",
119 f.getUser());
120 assertEquals("dir1",
121 f.getName());
122 assertEquals(36864,
123 f.getSize());
124
125 Calendar cal = Calendar.getInstance();
126 cal.set(Calendar.MONTH, Calendar.MARCH);
127
128 cal.set(Calendar.YEAR, 2004);
129 cal.set(Calendar.DATE, 24);
130 cal.set(Calendar.HOUR_OF_DAY, 14);
131 cal.set(Calendar.MINUTE, 6);
132 cal.set(Calendar.SECOND, 34);
133
134 assertEquals(df.format(cal.getTime()),
135 df.format(f.getTimestamp().getTime()));
136 }
137
138 @Override
139 protected void doAdditionalGoodTests(String test, FTPFile f)
140 {
141 if (test.startsWith("d"))
142 {
143 assertEquals("directory.type",
144 FTPFile.DIRECTORY_TYPE, f.getType());
145 }
146 }
147
148 /**
149 * @see FTPParseTestFramework#testParseFieldsOnFile()
150 */
151 @Override
152 public void testParseFieldsOnFile() throws Exception
153 {
154 FTPFile f = getParser().parseFTPEntry("PEP 5000000000 04/03/24 14:06:29 *STMF build.xml");
155 assertNotNull("Could not parse entry.",
156 f);
157 assertTrue("Should have been a file.",
158 f.isFile());
159 assertEquals("PEP",
160 f.getUser());
161 assertEquals("build.xml",
162 f.getName());
163 assertEquals(5000000000L,
164 f.getSize());
165
166 Calendar cal = Calendar.getInstance();
167
168 cal.set(Calendar.DATE, 24);
169 cal.set(Calendar.MONTH, Calendar.MARCH);
170 cal.set(Calendar.YEAR, 2004);
171 cal.set(Calendar.HOUR_OF_DAY, 14);
172 cal.set(Calendar.MINUTE, 6);
173 cal.set(Calendar.SECOND, 29);
174 assertEquals(df.format(cal.getTime()),
175 df.format(f.getTimestamp().getTime()));
176 }
177
178 /**
179 * Method suite.
180 *
181 * @return TestSuite
182 */
183 public static TestSuite suite()
184 {
185 return(new TestSuite(OS400FTPEntryParserTest.class));
186 }
187 }