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 org.apache.commons.net.ftp.FTPFile;
20  import org.apache.commons.net.ftp.FTPFileEntryParser;
21  import org.junit.jupiter.api.Test;
22  
23  /**
24   */
25  class MLSxEntryParserTest extends AbstractFTPParseTest {
26  
27      private static final String[] badsamples = { "Type=cdir;Modify=20141022065101;UNIX.mode=0775;/no/space", // no space between facts and name
28              "Type=cdir;Modify=20141022065103;UNIX.mode=0775;", // no name or space
29              "/no/leading/space", "", // empty
30              "Type=cdir;Modify=20141022065102;UNIX.mode=0775; ", // no name
31              "Type=dir;Size; missing =size", "Type=dir missing-semicolon", "Type= missing value and semicolon", " ", // no path
32              "Modify=2014; Short stamp", "Type=pdir;Modify=20141205180002Z; /trailing chars in Modify",
33              "Type=dir;Modify=2014102206510x2.999;UNIX.mode=0775; modify has spurious chars", };
34  
35      private static final String[] goodsamples = { "Type=cdir;Modify=20141022065102;UNIX.mode=0775; /commons/net",
36              "Type=pdir;Modify=20141205180002;UNIX.mode=0775; /commons", "Type=file;Size=431;Modify=20130303210732;UNIX.mode=0664; HEADER.html",
37              "Type=file;Size=1880;Modify=20130611172748;UNIX.mode=0664; README.html",
38              "Type=file;Size=2364;Modify=20130611170131;UNIX.mode=0664; RELEASE-NOTES.txt", "Type=dir;Modify=20141022065102;UNIX.mode=0775; binaries",
39              "Type=dir;Modify=20141022065102.999;UNIX.mode=0775; source", " /no/facts", // no facts
40              "Type=; /empty/fact", "Size=; /empty/size", " Type=cdir;Modify=20141022065102;UNIX.mode=0775; /leading/space", // leading space before facts => it's
41                                                                                                                             // a file name!
42              "  ", // pathname of space
43      };
44  
45      @Override
46      protected String[] getBadListing() {
47          return badsamples;
48      }
49  
50      @Override
51      protected String[] getGoodListing() {
52          return goodsamples;
53      }
54  
55      @Override
56      protected FTPFileEntryParser getParser() {
57          return MLSxEntryParser.getInstance();
58      }
59  
60      /**
61       * Check if FTPFile entry parsing failed; i.e. if entry is null. We override parent check, as a null timestamp is not acceptable for these tests.
62       *
63       * @param f FTPFile entry - may be null
64       * @return null if f is null
65       */
66      @Override
67      protected FTPFile nullFileOrNullDate(final FTPFile f) {
68          return f;
69      }
70  
71      @Override
72      @Test
73      void testDefaultPrecision() {
74          testPrecision("Type=dir;Modify=20141022065102;UNIX.mode=0775; source", CalendarUnit.SECOND);
75      }
76  
77      @Override
78      @Test
79      void testParseFieldsOnDirectory() throws Exception {
80      }
81  
82      @Override
83      @Test
84      void testParseFieldsOnFile() throws Exception {
85      }
86  
87      @Override
88      @Test
89      void testRecentPrecision() { // borrow this method to test milliseconds
90          testPrecision("Type=dir;Modify=20141022065102.999;UNIX.mode=0775; source", CalendarUnit.MILLISECOND);
91      }
92  }