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