View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.net.ftp.parser;
18  
19  import org.apache.commons.net.ftp.FTPFile;
20  import org.apache.commons.net.ftp.FTPFileEntryParser;
21  
22  /**
23   * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
24   * @version $Id: OS2FTPEntryParserTest.java 1299238 2012-03-10 17:12:28Z sebb $
25   */
26  public class OS2FTPEntryParserTest extends FTPParseTestFramework
27  {
28  
29      private static final String[] badsamples =
30      {
31          "                 DIR   12-30-97   12:32  jbrekke",
32          "     0    rsa    DIR   11-25-97   09:42  junk",
33          "     0           dir   05-12-97   16:44  LANGUAGE",
34          "     0           DIR   13-05-97   25:49  MPTN",
35          "587823    RSA    DIR   Jan-08-97   13:58  OS2KRNL",
36          " 33280      A          1997-02-03  13:49  OS2LDR",
37          "12-05-96  05:03PM       <DIR>          absoft2",
38          "11-14-97  04:21PM                  953 AUDITOR3.INI"
39      };
40      private static final String[] goodsamples =
41      {
42          "     0           DIR   12-30-97   12:32  jbrekke",
43          "     0           DIR   11-25-97   09:42  junk",
44          "     0           DIR   05-12-97   16:44  LANGUAGE",
45          "     0           DIR   05-19-97   12:56  local",
46          "     0           DIR   05-12-97   16:52  Maintenance Desktop",
47          "     0           DIR   05-13-97   10:49  MPTN",
48          "587823    RSA    DIR   01-08-97   13:58  OS2KRNL",
49          " 33280      A          02-09-97   13:49  OS2LDR",
50          "     0           DIR   11-28-97   09:42  PC",
51          "149473      A          11-17-98   16:07  POPUPLOG.OS2",
52          "     0           DIR   05-12-97   16:44  PSFONTS",
53          "     0           DIR   05-19-2000 12:56  local",
54      };
55  
56      /**
57       * @see junit.framework.TestCase#TestCase(String)
58       */
59      public OS2FTPEntryParserTest(String name)
60      {
61          super(name);
62      }
63  
64      /**
65       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
66       */
67      @Override
68      public void testParseFieldsOnDirectory() throws Exception
69      {
70          FTPFile dir = getParser().parseFTPEntry("     0           DIR   11-28-97   09:42  PC");
71          assertNotNull("Could not parse entry.", dir);
72          assertTrue("Should have been a directory.",
73                     dir.isDirectory());
74          assertEquals(0,dir.getSize());
75          assertEquals("PC", dir.getName());
76          assertEquals("Fri Nov 28 09:42:00 1997",
77                       df.format(dir.getTimestamp().getTime()));
78      }
79  
80      /**
81       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
82       */
83      @Override
84      public void testParseFieldsOnFile() throws Exception
85      {
86          FTPFile file = getParser().parseFTPEntry("5000000000      A          11-17-98   16:07  POPUPLOG.OS2");
87          assertNotNull("Could not parse entry.", file);
88          assertTrue("Should have been a file.",
89                     file.isFile());
90          assertEquals(5000000000L, file.getSize());
91          assertEquals("POPUPLOG.OS2", file.getName());
92          assertEquals("Tue Nov 17 16:07:00 1998",
93                       df.format(file.getTimestamp().getTime()));
94      }
95  
96      /**
97       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
98       */
99      @Override
100     protected String[] getBadListing()
101     {
102 
103         return (badsamples);
104     }
105 
106     /**
107      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
108      */
109     @Override
110     protected String[] getGoodListing()
111     {
112 
113         return (goodsamples);
114     }
115 
116     /**
117      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
118      */
119     @Override
120     protected FTPFileEntryParser getParser()
121     {
122         ConfigurableFTPFileEntryParserImpl parser =
123             new OS2FTPEntryParser();
124         parser.configure(null);
125         return parser;
126     }
127 }