    1   /*
    2    * Copyright 2001-2005 The Apache Software Foundation
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *     http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.net.ftp.parser;
    17
    18  import junit.framework.TestSuite;
    19
    20  import org.apache.commons.net.ftp.FTPFile;
    21  import org.apache.commons.net.ftp.FTPFileEntryParser;
    22
    23  /***
    24   * @author <a href="mailto:scohen@apache.org">Steve Cohen</a>
    25   * @version $Id: OS2FTPEntryParserTest.java 155429 2005-02-26 13:13:04Z dirkv $
    26   */
    27  public class OS2FTPEntryParserTest extends FTPParseTestFramework
    28  {
    29
    30      private static final String[] badsamples =
    31      {
    32          "                 DIR   12-30-97   12:32  jbrekke",
    33          "     0    rsa    DIR   11-25-97   09:42  junk",
    34          "     0           dir   05-12-97   16:44  LANGUAGE",
    35          "     0           DIR   13-05-97   25:49  MPTN",
    36          "587823    RSA    DIR   Jan-08-97   13:58  OS2KRNL",
    37          " 33280      A          1997-02-03  13:49  OS2LDR",
    38          "12-05-96  05:03PM       <DIR>          absoft2",
    39          "11-14-97  04:21PM                  953 AUDITOR3.INI"
    40      };
    41      private static final String[] goodsamples =
    42      {
    43          "     0           DIR   12-30-97   12:32  jbrekke",
    44          "     0           DIR   11-25-97   09:42  junk",
    45          "     0           DIR   05-12-97   16:44  LANGUAGE",
    46          "     0           DIR   05-19-97   12:56  local",
    47          "     0           DIR   05-12-97   16:52  Maintenance Desktop",
    48          "     0           DIR   05-13-97   10:49  MPTN",
    49          "587823    RSA    DIR   01-08-97   13:58  OS2KRNL",
    50          " 33280      A          02-09-97   13:49  OS2LDR",
    51          "     0           DIR   11-28-97   09:42  PC",
    52          "149473      A          11-17-98   16:07  POPUPLOG.OS2",
    53          "     0           DIR   05-12-97   16:44  PSFONTS",
    54          "     0           DIR   05-19-2000 12:56  local",
    55      };
    56
    57      /***
    58       * @see junit.framework.TestCase#TestCase(String)
    59       */
    60      public OS2FTPEntryParserTest(String name)
    61      {
    62          super(name);
    63      }
    64
    65      /***
    66       * Method suite.
    67       * @return TestSuite
    68       */
    69      public static TestSuite suite()
    70      {
    71
    72          return (new TestSuite(OS2FTPEntryParserTest.class));
    73      }
    74
    75      /***
    76       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
    77       */
    78      public void testParseFieldsOnDirectory() throws Exception
    79      {
    80          FTPFile dir = getParser().parseFTPEntry("     0           DIR   11-28-97   09:42  PC");
    81          assertNotNull("Could not parse entry.", dir);
    82          assertTrue("Should have been a directory.",
    83                     dir.isDirectory());
    84          assertEquals(0,dir.getSize());
    85          assertEquals("PC", dir.getName());
    86          assertEquals("Fri Nov 28 09:42:00 1997",
    87                       df.format(dir.getTimestamp().getTime()));
    88      }
    89
    90      /***
    91       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
    92       */
    93      public void testParseFieldsOnFile() throws Exception
    94      {
    95          FTPFile file = getParser().parseFTPEntry("5000000000      A          11-17-98   16:07  POPUPLOG.OS2");
    96          assertNotNull("Could not parse entry.", file);
    97          assertTrue("Should have been a file.",
    98                     file.isFile());
    99          assertEquals(5000000000L, file.getSize());
    100         assertEquals("POPUPLOG.OS2", file.getName());
    101         assertEquals("Tue Nov 17 16:07:00 1998",
    102                      df.format(file.getTimestamp().getTime()));
    103     }
    104
    105     /***
    106      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
    107      */
    108     protected String[] getBadListing()
    109     {
    110
    111         return (badsamples);
    112     }
    113
    114     /***
    115      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
    116      */
    117     protected String[] getGoodListing()
    118     {
    119
    120         return (goodsamples);
    121     }
    122
    123     /***
    124      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
    125      */
    126     protected FTPFileEntryParser getParser()
    127     {
    128         ConfigurableFTPFileEntryParserImpl parser =
    129             new OS2FTPEntryParser();
    130         parser.configure(null);
    131         return parser;
    132     }
    133 }