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  public class OS2FTPEntryParserTest extends AbstractFTPParseTest {
23  
24      private static final String[] badsamples = { "                 DIR   12-30-97   12:32  jbrekke", "     0    rsa    DIR   11-25-97   09:42  junk",
25              "     0           dir   05-12-97   16:44  LANGUAGE", "     0           DIR   13-05-97   25:49  MPTN",
26              "587823    RSA    DIR   Jan-08-97   13:58  OS2KRNL", " 33280      A          1997-02-03  13:49  OS2LDR",
27              "12-05-96  05:03PM       <DIR>          absoft2", "11-14-97  04:21PM                  953 AUDITOR3.INI" };
28  
29      private static final String[] goodsamples = { "     0           DIR   12-30-97   12:32  jbrekke", "     0           DIR   11-25-97   09:42  junk",
30              "     0           DIR   05-12-97   16:44  LANGUAGE", "     0           DIR   05-19-97   12:56  local",
31              "     0           DIR   05-12-97   16:52  Maintenance Desktop", "     0           DIR   05-13-97   10:49  MPTN",
32              "587823    RSA    DIR   01-08-97   13:58  OS2KRNL", " 33280      A          02-09-97   13:49  OS2LDR",
33              "     0           DIR   11-28-97   09:42  PC", "149473      A          11-17-98   16:07  POPUPLOG.OS2",
34              "     0           DIR   05-12-97   16:44  PSFONTS", "     0           DIR   05-19-2000 12:56  local", };
35  
36      public OS2FTPEntryParserTest(final String name) {
37          super(name);
38      }
39  
40      @Override
41      protected String[] getBadListing() {
42  
43          return badsamples;
44      }
45  
46      @Override
47      protected String[] getGoodListing() {
48  
49          return goodsamples;
50      }
51  
52      @Override
53      protected FTPFileEntryParser getParser() {
54          final ConfigurableFTPFileEntryParserImpl parser = new OS2FTPEntryParser();
55          parser.configure(null);
56          return parser;
57      }
58  
59      @Override
60      public void testDefaultPrecision() {
61          testPrecision("     0           DIR   05-12-97   16:44  PSFONTS", CalendarUnit.MINUTE);
62          testPrecision("     0           DIR   05-19-2000 12:56  local", CalendarUnit.MINUTE);
63      }
64  
65      @Override
66      public void testParseFieldsOnDirectory() throws Exception {
67          final FTPFile dir = getParser().parseFTPEntry("     0           DIR   11-28-97   09:42  PC");
68          assertNotNull("Could not parse entry.", dir);
69          assertTrue("Should have been a directory.", dir.isDirectory());
70          assertEquals(0, dir.getSize());
71          assertEquals("PC", dir.getName());
72          assertEquals("Fri Nov 28 09:42:00 1997", df.format(dir.getTimestamp().getTime()));
73      }
74  
75      @Override
76      public void testParseFieldsOnFile() throws Exception {
77          final FTPFile file = getParser().parseFTPEntry("5000000000      A          11-17-98   16:07  POPUPLOG.OS2");
78          assertNotNull("Could not parse entry.", file);
79          assertTrue("Should have been a file.", file.isFile());
80          assertEquals(5000000000L, file.getSize());
81          assertEquals("POPUPLOG.OS2", file.getName());
82          assertEquals("Tue Nov 17 16:07:00 1998", df.format(file.getTimestamp().getTime()));
83      }
84  
85      @Override
86      public void testRecentPrecision() {
87          // Not needed
88      }
89  }