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 java.util.Calendar;
020
021 import junit.framework.TestSuite;
022
023 import org.apache.commons.net.ftp.FTPFile;
024 import org.apache.commons.net.ftp.FTPFileEntryParser;
025
026 /**
027 * Tests the EnterpriseUnixFTPEntryParser
028 *
029 * @version $Id: EnterpriseUnixFTPEntryParserTest.java 437134 2006-08-26 09:36:36Z rwinston $
030 * @author <a href="mailto:Winston.Ojeda@qg.com">Winston Ojeda</a>
031 */
032 public class EnterpriseUnixFTPEntryParserTest extends FTPParseTestFramework
033 {
034
035 private static final String[] BADSAMPLES =
036 {
037 "zrwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox",
038 "dxrwr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc",
039 "drwxr-xr-x 2 root root 4096 Jam 4 00:03 zziplib",
040 "drwxr-xr-x 2 root 99 4096 Feb 23 30:01 zzplayer",
041 "drwxr-xr-x 2 root root 4096 Aug 36 2001 zztpp",
042 "-rw-r--r-- 1 14 staff 80284 Aug 22 zxJDBC-1.2.3.tar.gz",
043 "-rw-r--r-- 1 14 staff 119:26 Aug 22 2000 zxJDBC-1.2.3.zip",
044 "-rw-r--r-- 1 ftp no group 83853 Jan 22 2001 zxJDBC-1.2.4.tar.gz",
045 "-rw-r--r-- 1ftp nogroup 126552 Jan 22 2001 zxJDBC-1.2.4.zip",
046 "-rw-r--r-- 1 root root 111325 Apr -7 18:79 zxJDBC-2.0.1b1.tar.gz",
047 "drwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox",
048 "drwxr-xr-x 1 usernameftp 512 Jan 29 23:32 prog",
049 "drwxr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc",
050 "drwxr-xr-x 2 root root 4096 Jan 4 00:03 zziplib",
051 "drwxr-xr-x 2 root 99 4096 Feb 23 2001 zzplayer",
052 "drwxr-xr-x 2 root root 4096 Aug 6 2001 zztpp",
053 "-rw-r--r-- 1 14 staff 80284 Aug 22 2000 zxJDBC-1.2.3.tar.gz",
054 "-rw-r--r-- 1 14 staff 119926 Aug 22 2000 zxJDBC-1.2.3.zip",
055 "-rw-r--r-- 1 ftp nogroup 83853 Jan 22 2001 zxJDBC-1.2.4.tar.gz",
056 "-rw-r--r-- 1 ftp nogroup 126552 Jan 22 2001 zxJDBC-1.2.4.zip",
057 "-rw-r--r-- 1 root root 111325 Apr 27 2001 zxJDBC-2.0.1b1.tar.gz",
058 "-rw-r--r-- 1 root root 190144 Apr 27 2001 zxJDBC-2.0.1b1.zip"
059 };
060 private static final String[] GOODSAMPLES =
061 {
062 "-C--E-----FTP B QUA1I1 18128 41 Aug 12 13:56 QUADTEST",
063 "-C--E-----FTP A QUA1I1 18128 41 Aug 12 13:56 QUADTEST2"
064 };
065
066 /**
067 * Creates a new EnterpriseUnixFTPEntryParserTest object.
068 *
069 * @param name Test name.
070 */
071 public EnterpriseUnixFTPEntryParserTest(String name)
072 {
073 super(name);
074 }
075
076 /**
077 * Method suite.
078 *
079 * @return TestSuite
080 */
081 public static TestSuite suite()
082 {
083
084 return (new TestSuite(EnterpriseUnixFTPEntryParserTest.class));
085 }
086
087 /**
088 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
089 */
090 @Override
091 public void testParseFieldsOnDirectory() throws Exception
092 {
093 // Everything is a File for now.
094 }
095
096 /**
097 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
098 */
099 @Override
100 public void testParseFieldsOnFile() throws Exception
101 {
102 FTPFile file = getParser().parseFTPEntry("-C--E-----FTP B QUA1I1 18128 5000000000 Aug 12 13:56 QUADTEST");
103 Calendar today = Calendar.getInstance();
104 int year = today.get(Calendar.YEAR);
105
106 assertTrue("Should be a file.",
107 file.isFile());
108 assertEquals("QUADTEST",
109 file.getName());
110 assertEquals(5000000000L,
111 file.getSize());
112 assertEquals("QUA1I1",
113 file.getUser());
114 assertEquals("18128",
115 file.getGroup());
116
117 if(today.get(Calendar.MONTH) < Calendar.AUGUST)
118 --year;
119
120 Calendar timestamp = file.getTimestamp();
121 assertEquals(year, timestamp.get(Calendar.YEAR));
122 assertEquals(Calendar.AUGUST, timestamp.get(Calendar.MONTH));
123 assertEquals(12, timestamp.get(Calendar.DAY_OF_MONTH));
124 assertEquals(13, timestamp.get(Calendar.HOUR_OF_DAY));
125 assertEquals(56, timestamp.get(Calendar.MINUTE));
126 assertEquals(0, timestamp.get(Calendar.SECOND));
127
128 checkPermisions(file);
129 }
130
131 /**
132 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
133 */
134 @Override
135 protected String[] getBadListing()
136 {
137
138 return (BADSAMPLES);
139 }
140
141 /**
142 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
143 */
144 @Override
145 protected String[] getGoodListing()
146 {
147
148 return (GOODSAMPLES);
149 }
150
151 /**
152 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
153 */
154 @Override
155 protected FTPFileEntryParser getParser()
156 {
157
158 return (new EnterpriseUnixFTPEntryParser());
159 }
160
161 /**
162 * Method checkPermisions. Verify that the parser does NOT set the
163 * permissions.
164 *
165 * @param dir
166 */
167 private void checkPermisions(FTPFile dir)
168 {
169 assertTrue("Owner should not have read permission.",
170 !dir.hasPermission(FTPFile.USER_ACCESS,
171 FTPFile.READ_PERMISSION));
172 assertTrue("Owner should not have write permission.",
173 !dir.hasPermission(FTPFile.USER_ACCESS,
174 FTPFile.WRITE_PERMISSION));
175 assertTrue("Owner should not have execute permission.",
176 !dir.hasPermission(FTPFile.USER_ACCESS,
177 FTPFile.EXECUTE_PERMISSION));
178 assertTrue("Group should not have read permission.",
179 !dir.hasPermission(FTPFile.GROUP_ACCESS,
180 FTPFile.READ_PERMISSION));
181 assertTrue("Group should not have write permission.",
182 !dir.hasPermission(FTPFile.GROUP_ACCESS,
183 FTPFile.WRITE_PERMISSION));
184 assertTrue("Group should not have execute permission.",
185 !dir.hasPermission(FTPFile.GROUP_ACCESS,
186 FTPFile.EXECUTE_PERMISSION));
187 assertTrue("World should not have read permission.",
188 !dir.hasPermission(FTPFile.WORLD_ACCESS,
189 FTPFile.READ_PERMISSION));
190 assertTrue("World should not have write permission.",
191 !dir.hasPermission(FTPFile.WORLD_ACCESS,
192 FTPFile.WRITE_PERMISSION));
193 assertTrue("World should not have execute permission.",
194 !dir.hasPermission(FTPFile.WORLD_ACCESS,
195 FTPFile.EXECUTE_PERMISSION));
196 }
197 }
198
199 /* Emacs configuration
200 * Local variables: **
201 * mode: java **
202 * c-basic-offset: 4 **
203 * indent-tabs-mode: nil **
204 * End: **
205 */