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