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 junit.framework.TestSuite;
20  
21  import org.apache.commons.net.ftp.FTPFile;
22  import org.apache.commons.net.ftp.FTPFileEntryParser;
23  
24  /**
25   * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
26   * @version $Id: OS2FTPEntryParserTest.java 437134 2006-08-26 09:36:36Z rwinston $
27   */
28  public class OS2FTPEntryParserTest extends FTPParseTestFramework
29  {
30  
31      private static final String[] badsamples =
32      {
33          "                 DIR   12-30-97   12:32  jbrekke",
34          "     0    rsa    DIR   11-25-97   09:42  junk",
35          "     0           dir   05-12-97   16:44  LANGUAGE",
36          "     0           DIR   13-05-97   25:49  MPTN",
37          "587823    RSA    DIR   Jan-08-97   13:58  OS2KRNL",
38          " 33280      A          1997-02-03  13:49  OS2LDR",
39          "12-05-96  05:03PM       <DIR>          absoft2",
40          "11-14-97  04:21PM                  953 AUDITOR3.INI"
41      };
42      private static final String[] goodsamples =
43      {
44          "     0           DIR   12-30-97   12:32  jbrekke",
45          "     0           DIR   11-25-97   09:42  junk",
46          "     0           DIR   05-12-97   16:44  LANGUAGE",
47          "     0           DIR   05-19-97   12:56  local",
48          "     0           DIR   05-12-97   16:52  Maintenance Desktop",
49          "     0           DIR   05-13-97   10:49  MPTN",
50          "587823    RSA    DIR   01-08-97   13:58  OS2KRNL",
51          " 33280      A          02-09-97   13:49  OS2LDR",
52          "     0           DIR   11-28-97   09:42  PC",
53          "149473      A          11-17-98   16:07  POPUPLOG.OS2",
54          "     0           DIR   05-12-97   16:44  PSFONTS",
55          "     0           DIR   05-19-2000 12:56  local",
56      };
57  
58      /**
59       * @see junit.framework.TestCase#TestCase(String)
60       */
61      public OS2FTPEntryParserTest(String name)
62      {
63          super(name);
64      }
65  
66      /**
67       * Method suite.
68       * @return TestSuite
69       */
70      public static TestSuite suite()
71      {
72  
73          return (new TestSuite(OS2FTPEntryParserTest.class));
74      }
75  
76      /**
77       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
78       */
79      @Override
80      public void testParseFieldsOnDirectory() throws Exception
81      {
82          FTPFile dir = getParser().parseFTPEntry("     0           DIR   11-28-97   09:42  PC");
83          assertNotNull("Could not parse entry.", dir);
84          assertTrue("Should have been a directory.",
85                     dir.isDirectory());
86          assertEquals(0,dir.getSize());
87          assertEquals("PC", dir.getName());
88          assertEquals("Fri Nov 28 09:42:00 1997",
89                       df.format(dir.getTimestamp().getTime()));
90      }
91  
92      /**
93       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
94       */
95      @Override
96      public void testParseFieldsOnFile() throws Exception
97      {
98          FTPFile file = getParser().parseFTPEntry("5000000000      A          11-17-98   16:07  POPUPLOG.OS2");
99          assertNotNull("Could not parse entry.", file);
100         assertTrue("Should have been a file.",
101                    file.isFile());
102         assertEquals(5000000000L, file.getSize());
103         assertEquals("POPUPLOG.OS2", file.getName());
104         assertEquals("Tue Nov 17 16:07:00 1998",
105                      df.format(file.getTimestamp().getTime()));
106     }
107 
108     /**
109      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
110      */
111     @Override
112     protected String[] getBadListing()
113     {
114 
115         return (badsamples);
116     }
117 
118     /**
119      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
120      */
121     @Override
122     protected String[] getGoodListing()
123     {
124 
125         return (goodsamples);
126     }
127 
128     /**
129      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
130      */
131     @Override
132     protected FTPFileEntryParser getParser()
133     {
134         ConfigurableFTPFileEntryParserImpl parser =
135             new OS2FTPEntryParser();
136         parser.configure(null);
137         return parser;
138     }
139 }