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