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