scohen      2004/04/15 18:52:24

  Modified:    net/src/test/org/apache/commons/net/ftp/parser
                        FTPParseTestFramework.java
                        OS400FTPEntryParserTest.java
                        DefaultFTPFileEntryParserFactoryTest.java
                        NTFTPEntryParserTest.java
               net/src/java/org/apache/commons/net/ftp/parser
                        DefaultFTPFileEntryParserFactory.java
  Added:       net/src/test/org/apache/commons/net/ftp/parser
                        CompositeFTPParseTestFramework.java
  Log:
  OS400 also has the abillity to change the dirstyle to unix.  This patch
  enables this feature and generalizes the Composite pattern originally
  introduced for NT.
  PR: 28247
  Submitted by: [EMAIL PROTECTED] (Mario Ivankovits)
  Reviewed by:  Steve Cohen
  
  Revision  Changes    Path
  1.7       +26 -2     
jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/FTPParseTestFramework.java
  
  Index: FTPParseTestFramework.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/FTPParseTestFramework.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FTPParseTestFramework.java        10 Mar 2004 03:37:16 -0000      1.6
  +++ FTPParseTestFramework.java        16 Apr 2004 01:52:24 -0000      1.7
  @@ -13,7 +13,7 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  -package org.apache.commons.net.ftp.parser;

  +package org.apache.commons.net.ftp.parser;
   import junit.framework.TestCase;
   
   import java.text.SimpleDateFormat;
  @@ -54,6 +54,8 @@
               FTPFile f = parser.parseFTPEntry(test);
               assertNull("Should have Failed to parse " + test, 
                          f);
  +
  +            doAdditionalBadTests(test, f);
           }
       }
   
  @@ -73,7 +75,29 @@
               FTPFile f = parser.parseFTPEntry(test);
               assertNotNull("Failed to parse " + test, 
                             f);
  +
  +            doAdditionalGoodTests(test, f);
  +        }
  +    }
  +
  +    /**
  +     * during processing you could hook here to do additional tests
  +     *
  +     * @param test raw entry
  +     * @param f    parsed entry
  +     */
  +    protected void doAdditionalGoodTests(String test, FTPFile f)
  +    {
           }
  +
  +    /**
  +     * during processing you could hook here to do additional tests
  +     *
  +     * @param test raw entry
  +     * @param f    parsed entry
  +     */
  +    protected void doAdditionalBadTests(String test, FTPFile f)
  +    {
       }
   
       /**
  
  
  
  1.2       +180 -148  
jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java
  
  Index: OS400FTPEntryParserTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OS400FTPEntryParserTest.java      26 Mar 2004 12:54:57 -0000      1.1
  +++ OS400FTPEntryParserTest.java      16 Apr 2004 01:52:24 -0000      1.2
  @@ -1,148 +1,180 @@
  -/*

  - * Copyright 2004 The Apache Software Foundation

  - *

  - * Licensed under the Apache License, Version 2.0 (the "License");

  - * you may not use this file except in compliance with the License.

  - * You may obtain a copy of the License at

  - *

  - *     http://www.apache.org/licenses/LICENSE-2.0

  - *

  - * Unless required by applicable law or agreed to in writing, software

  - * distributed under the License is distributed on an "AS IS" BASIS,

  - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  - * See the License for the specific language governing permissions and

  - * limitations under the License.

  - */

  -package org.apache.commons.net.ftp.parser;

  -import java.util.Calendar;

  -

  -import junit.framework.TestSuite;

  -

  -import org.apache.commons.net.ftp.FTPFile;

  -import org.apache.commons.net.ftp.FTPFileEntryParser;

  -

  -/**

  - * @version $Id$

  - */

  -

  -public class OS400FTPEntryParserTest extends FTPParseTestFramework

  -{

  -

  -    private static final String[] badsamples =

  -    {

  -             "PEP              4019 04/03/18 18:58:16 STMF       einladung.zip",

  -             "PEP               422 03/24 14:06:26 *STMF      readme",

  -             "PEP              6409 04/03/24 30:06:29 *STMF      build.xml",

  -             "PEP USR         36864 04/03/24 14:06:34 *DIR       dir1/",

  -             "PEP             3686404/03/24 14:06:47 *DIR       zdir2/"

  -    };

  -

  -    private static final String[] goodsamples =

  -    {

  -             "PEP              4019 04/03/18 18:58:16 *STMF      einladung.zip",

  -             "PEP               422 04/03/24 14:06:26 *STMF      readme",

  -             "PEP              6409 04/03/24 14:06:29 *STMF      build.xml",

  -             "PEP             36864 04/03/24 14:06:34 *DIR       dir1/",

  -             "PEP             36864 04/03/24 14:06:47 *DIR       zdir2/"

  -    };

  -

  -    /**

  -     * @see junit.framework.TestCase#TestCase(String)

  -     */

  -    public OS400FTPEntryParserTest(String name)

  -    {

  -        super(name);

  -    }

  -

  -    /**

  -     * @see FTPParseTestFramework#getBadListing()

  -     */

  -    protected String[] getBadListing()

  -    {

  -        return(badsamples);

  -    }

  -

  -    /**

  -     * @see FTPParseTestFramework#getGoodListing()

  -     */

  -    protected String[] getGoodListing()

  -    {

  -        return(goodsamples);

  -    }

  -

  -    /**

  -     * @see FTPParseTestFramework#getParser()

  -     */

  -    protected FTPFileEntryParser getParser()

  -    {

  -        return(new OS400FTPEntryParser());

  -    }

  -

  -    /**

  -     * @see FTPParseTestFramework#testParseFieldsOnDirectory()

  -     */

  -    public void testParseFieldsOnDirectory() throws Exception

  -    {

  -        FTPFile f = getParser().parseFTPEntry("PEP             36864 04/03/24 
14:06:34 *DIR       dir1/");

  -        assertNotNull("Could not parse entry.",

  -                      f);

  -        assertTrue("Should have been a directory.",

  -                   f.isDirectory());

  -        assertEquals("PEP",

  -                     f.getUser());

  -        assertEquals("dir1",

  -                     f.getName());

  -        assertEquals(36864,

  -                     f.getSize());

  -

  -        Calendar cal = Calendar.getInstance();

  -        cal.set(Calendar.MONTH, Calendar.MARCH);

  -

  -        cal.set(Calendar.YEAR, 2004);

  -             cal.set(Calendar.DATE, 24);

  -        cal.set(Calendar.HOUR_OF_DAY, 14);

  -             cal.set(Calendar.MINUTE, 6);

  -        cal.set(Calendar.SECOND, 34);

  -

  -        assertEquals(df.format(cal.getTime()),

  -                     df.format(f.getTimestamp().getTime()));

  -    }

  -

  -    /**

  -     * @see FTPParseTestFramework#testParseFieldsOnFile()

  -     */

  -    public void testParseFieldsOnFile() throws Exception

  -    {

  -        FTPFile f = getParser().parseFTPEntry("PEP              6409 04/03/24 
14:06:29 *STMF      build.xml");

  -        assertNotNull("Could not parse entry.",

  -                      f);

  -        assertTrue("Should have been a file.",

  -                   f.isFile());

  -        assertEquals("PEP",

  -                     f.getUser());

  -        assertEquals("build.xml",

  -                     f.getName());

  -        assertEquals(6409,

  -                     f.getSize());

  -

  -        Calendar cal = Calendar.getInstance();

  -

  -        cal.set(Calendar.DATE, 24);

  -             cal.set(Calendar.MONTH, Calendar.MARCH);

  -        cal.set(Calendar.YEAR, 2004);

  -        cal.set(Calendar.HOUR_OF_DAY, 14);

  -        cal.set(Calendar.MINUTE, 6);

  -             cal.set(Calendar.SECOND, 29);

  -        assertEquals(df.format(cal.getTime()),

  -                     df.format(f.getTimestamp().getTime()));

  -    }

  -

  -    /**

  -     * Method suite.

  -     * @return TestSuite

  -     */

  -    public static TestSuite suite()

  -    {

  -        return(new TestSuite(OS400FTPEntryParserTest.class));

  -    }

  -}

  +/*
  + * Copyright 2004 The Apache Software Foundation
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
  +package org.apache.commons.net.ftp.parser;
  +
  +import junit.framework.TestSuite;
  +import org.apache.commons.net.ftp.FTPFile;
  +import org.apache.commons.net.ftp.FTPFileEntryParser;
  +
  +import java.util.Calendar;
  +
  +/**
  + * @version $Id$
  + */
  +
  +public class OS400FTPEntryParserTest extends CompositeFTPParseTestFramework
  +{
  +    private static final String[][] badsamples =
  +{
  +    {
  +             "PEP              4019 04/03/18 18:58:16 STMF       einladung.zip",
  +             "PEP               422 03/24 14:06:26 *STMF      readme",
  +             "PEP              6409 04/03/24 30:06:29 *STMF      build.xml",
  +             "PEP USR         36864 04/03/24 14:06:34 *DIR       dir1/",
  +             "PEP             3686404/03/24 14:06:47 *DIR       zdir2/"
  +            },
  +
  +            {
  +                "----rwxr-x   1PEP       0           4019 Mar 18 18:58 
einladung.zip",
  +                "----rwxr-x   1 PEP      0  xx        422 Mar 24 14:06 readme",
  +                "----rwxr-x   1 PEP      0           8492 Apr 07 30:13 build.xml",
  +                "d---rwxr-x   2 PEP USR  0          45056 Mar 24 14:06 dir1",
  +                "d---rwxr-x   2 PEP      0          45056Mar 24 14:06 zdir2"
  +            }
  +    };
  +
  +    private static final String[][] goodsamples =
  +        {
  +    {
  +             "PEP              4019 04/03/18 18:58:16 *STMF      einladung.zip",
  +             "PEP               422 04/03/24 14:06:26 *STMF      readme",
  +             "PEP              6409 04/03/24 14:06:29 *STMF      build.xml",
  +             "PEP             36864 04/03/24 14:06:34 *DIR       dir1/",
  +             "PEP             36864 04/03/24 14:06:47 *DIR       zdir2/"
  +            },
  +            {
  +                "----rwxr-x   1 PEP      0           4019 Mar 18 18:58 
einladung.zip",
  +                "----rwxr-x   1 PEP      0            422 Mar 24 14:06 readme",
  +                "----rwxr-x   1 PEP      0           8492 Apr 07 07:13 build.xml",
  +                "d---rwxr-x   2 PEP      0          45056 Mar 24 14:06 dir1",
  +                "d---rwxr-x   2 PEP      0          45056 Mar 24 14:06 zdir2"
  +            }
  +    };
  +
  +    /**
  +     * @see junit.framework.TestCase#TestCase(String)
  +     */
  +    public OS400FTPEntryParserTest(String name)
  +    {
  +        super(name);
  +    }
  +
  +    /**
  +     * @see FTPParseTestFramework#getBadListing()
  +     */
  +    protected String[][] getBadListings()
  +    {
  +        return badsamples;
  +    }
  +
  +    /**
  +     * @see FTPParseTestFramework#getGoodListing()
  +     */
  +    protected String[][] getGoodListings()
  +    {
  +        return goodsamples;
  +    }
  +
  +    /**
  +     * @see FTPParseTestFramework#getParser()
  +     */
  +    protected FTPFileEntryParser getParser()
  +    {
  +        return new CompositeFileEntryParser(new FTPFileEntryParser[]
  +        {
  +            new OS400FTPEntryParser(),
  +            new UnixFTPEntryParser()
  +        });
  +    }
  +
  +    /**
  +     * @see FTPParseTestFramework#testParseFieldsOnDirectory()
  +     */
  +    public void testParseFieldsOnDirectory() throws Exception
  +    {
  +        FTPFile f = getParser().parseFTPEntry("PEP             36864 04/03/24 
14:06:34 *DIR       dir1/");
  +        assertNotNull("Could not parse entry.",
  +                      f);
  +        assertTrue("Should have been a directory.",
  +                   f.isDirectory());
  +        assertEquals("PEP",
  +                     f.getUser());
  +        assertEquals("dir1",
  +                     f.getName());
  +        assertEquals(36864,
  +                     f.getSize());
  +
  +        Calendar cal = Calendar.getInstance();
  +        cal.set(Calendar.MONTH, Calendar.MARCH);
  +
  +        cal.set(Calendar.YEAR, 2004);
  +             cal.set(Calendar.DATE, 24);
  +        cal.set(Calendar.HOUR_OF_DAY, 14);
  +             cal.set(Calendar.MINUTE, 6);
  +        cal.set(Calendar.SECOND, 34);
  +
  +        assertEquals(df.format(cal.getTime()),
  +                     df.format(f.getTimestamp().getTime()));
  +    }
  +
  +    protected void doAdditionalGoodTests(String test, FTPFile f)
  +    {
  +        if (test.startsWith("d"))
  +        {
  +            assertEquals("directory.type",
  +                FTPFile.DIRECTORY_TYPE, f.getType());
  +        }
  +    }
  +
  +    /**
  +     * @see FTPParseTestFramework#testParseFieldsOnFile()
  +     */
  +    public void testParseFieldsOnFile() throws Exception
  +    {
  +        FTPFile f = getParser().parseFTPEntry("PEP              6409 04/03/24 
14:06:29 *STMF      build.xml");
  +        assertNotNull("Could not parse entry.",
  +                      f);
  +        assertTrue("Should have been a file.",
  +                   f.isFile());
  +        assertEquals("PEP",
  +                     f.getUser());
  +        assertEquals("build.xml",
  +                     f.getName());
  +        assertEquals(6409,
  +                     f.getSize());
  +
  +        Calendar cal = Calendar.getInstance();
  +
  +        cal.set(Calendar.DATE, 24);
  +             cal.set(Calendar.MONTH, Calendar.MARCH);
  +        cal.set(Calendar.YEAR, 2004);
  +        cal.set(Calendar.HOUR_OF_DAY, 14);
  +        cal.set(Calendar.MINUTE, 6);
  +             cal.set(Calendar.SECOND, 29);
  +        assertEquals(df.format(cal.getTime()),
  +                     df.format(f.getTimestamp().getTime()));
  +    }
  +
  +    /**
  +     * Method suite.
  +     *
  +     * @return TestSuite
  +     */
  +    public static TestSuite suite()
  +    {
  +        return(new TestSuite(OS400FTPEntryParserTest.class));
  +    }
  +}
  
  
  
  1.6       +1 -1      
jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java
  
  Index: DefaultFTPFileEntryParserFactoryTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultFTPFileEntryParserFactoryTest.java 6 Apr 2004 04:40:57 -0000       1.5
  +++ DefaultFTPFileEntryParserFactoryTest.java 16 Apr 2004 01:52:24 -0000      1.6
  @@ -59,7 +59,7 @@
           assertTrue(parser instanceof OS2FTPEntryParser);
   
           parser = factory.createFileEntryParser("OS/400");
  -        assertTrue(parser instanceof OS400FTPEntryParser);
  +        assertTrue(parser instanceof CompositeFileEntryParser);
           
           try {
               parser = factory.createFileEntryParser("OS2FTPFileEntryParser");
  
  
  
  1.10      +32 -60    
jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java
  
  Index: NTFTPEntryParserTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NTFTPEntryParserTest.java 6 Apr 2004 04:40:57 -0000       1.9
  +++ NTFTPEntryParserTest.java 16 Apr 2004 01:52:24 -0000      1.10
  @@ -14,16 +14,16 @@
    * limitations under the License.
    */
   package org.apache.commons.net.ftp.parser;
  -import org.apache.commons.net.ftp.FTPFile;
  -import org.apache.commons.net.ftp.FTPFileEntryParser;
   
   import junit.framework.TestSuite;
  +import org.apache.commons.net.ftp.FTPFile;
  +import org.apache.commons.net.ftp.FTPFileEntryParser;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Steve Cohen</a>
    * @version $Id$
    */
  -public class NTFTPEntryParserTest extends FTPParseTestFramework
  +public class NTFTPEntryParserTest extends CompositeFTPParseTestFramework
   {
   
       private static final String [][] goodsamples = { 
  @@ -47,17 +47,9 @@
        }
       };
       
  -    private static final String [] inconsistentsamples = {
  -     "-rw-r--r--   1 root     root       111325 Apr 27  2001 
zxJDBC-2.0.1b1.tar.gz", 
  -     "-rwxr-xr-x   2 500      500           166 Nov  2  2001 73131-testtes1.afp",
  -             "05-22-97  08:08AM                  828 AUTOEXEC.BAK",
  -             "01-22-98  01:52PM                  795 AUTOEXEC.BAT",
  -             "05-13-97  01:46PM                  828 AUTOEXEC.DOS",
  -             "12-03-96  06:38AM                  403 AUTOTOOL.LOG",
  -             
  -    };
  -
  -    private static final String [] badsamples = {
  +    private static final String[][] badsamples =
  +        {
  +            {
                   "05-26-1995  10:57AM               143712 $LDR$",
                   "20-05-97  03:31PM                  681 .bash_history",
                                "drwxr-xr-x   2 root     99           4096 Feb 23 
30:01 zzplayer",
  @@ -65,8 +57,18 @@
                   "05-22-97  08:08                    828 AUTOEXEC.BAK",
                   "     0           DIR   05-19-97   12:56  local",
                   "     0           DIR   05-12-97   16:52  Maintenance Desktop",
  -
  +            },
  +            {
  +                "05-26-1995  10:57AM               143712 $LDR$",
  +                "20-05-97  03:31PM                  681 .bash_history",
  +                "drwxr-xr-x   2 root     99           4096Feb 23 30:01 zzplayer",
  +                "12-05-96  17:03         <DIR>          absoft2",
  +                "05-22-97  08:08                    828 AUTOEXEC.BAK",
  +                "     0           DIR   05-19-97   12:56  local",
  +                "     0           DIR   05-12-97   16:52  Maintenance Desktop",
  +            }
               };
  +
       private static final String directoryBeginningWithNumber =
        "12-03-96  06:38AM       <DIR>          123xyz";
        
  @@ -80,19 +82,19 @@
       }
   
       /**
  -     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
  +     * @see 
org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings()
        */
  -    protected String[] getGoodListing()
  +    protected String[][] getGoodListings()
       {
  -        return(goodsamples[0]);
  +        return goodsamples;
       }
       
       /**
  -     * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
  +     * @see 
org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings()
        */
  -    protected String[] getBadListing()
  +    protected String[][] getBadListings()
       {
  -        return(badsamples);
  +        return badsamples;
       }
   
       /**
  @@ -109,6 +111,7 @@
       
       /**
        * Method suite.
  +     *
        * @return TestSuite
        */
       public static TestSuite suite()
  @@ -146,56 +149,25 @@
           assertEquals(828, f.getSize());   
       }
   
  -    /* (non-Javadoc)
  -      * @see 
org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
  -      */
  -     public void testConsistentListing() throws Exception {
  -             for (int i = 0; i < goodsamples.length; i++)
  +
  +    protected void doAdditionalGoodTests(String test, FTPFile f)
  +    {
  +        if (test.indexOf("<DIR>") >= 0)
                {
  -                     FTPFileEntryParser parser = getParser();
  -                     for (int j = 0; j < goodsamples[i].length; j++) {
  -                             String test = goodsamples[i][j];
  -                             FTPFile f = parser.parseFTPEntry(test);
  -                             assertNotNull("Failed to parse " + test, 
  -                                             f);
  -                             if (test.indexOf("<DIR>") >= 0) {
                                        assertEquals("directory.type", 
                                                        FTPFile.DIRECTORY_TYPE, 
f.getType());
                                }
  -                             
  -                     }
  -
  -             }
  -             
        }
        
  -     // even though all these listings are good using one parser
  -     // or the other, this tests that a parser that has succeeded
  -     // on one format will fail if another format is substituted.
  -     public void testInconsistentListing() throws Exception {
  -             FTPFileEntryParser parser = getParser();
  -             for (int i = 0; i < 2; i++)
  -             {
  -                     String test = inconsistentsamples[i];
  -                     FTPFile f = parser.parseFTPEntry(test);
  -                     assertNotNull("Failed to parse " + test, f);
  -             }
  -             for (int i = 2; i < inconsistentsamples.length; i++)
  -             {
  -                     String test = inconsistentsamples[i];
  -                     FTPFile f = parser.parseFTPEntry(test);
  -                     assertNull("Should have failed to parse " + test, f);
  -             }
  -     }
  -     
  -
        /**
         * test condition reported as bug 20259.
         * directory with name beginning with a numeric character
         * was not parsing correctly
  +     *
         * @throws Exception
         */
  -     public void testDirectoryBeginningWithNumber() throws Exception {
  +    public void testDirectoryBeginningWithNumber() throws Exception
  +    {
                FTPFile f = getParser().parseFTPEntry(directoryBeginningWithNumber);
                assertEquals("name", "123xyz", f.getName());
        }
  
  
  
  1.1                  
jakarta-commons/net/src/test/org/apache/commons/net/ftp/parser/CompositeFTPParseTestFramework.java
  
  Index: CompositeFTPParseTestFramework.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.net.ftp.parser;
  
  import org.apache.commons.net.ftp.FTPFile;
  import org.apache.commons.net.ftp.FTPFileEntryParser;
  
  /**
   * @author <a href="[EMAIL PROTECTED]">MarioIvankovits</a>
   * @version $Id: CompositeFTPParseTestFramework.java,v 1.1 2004/04/16 01:52:24 
scohen Exp $
   */
  public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework
  {
        /**
         * @see junit.framework.TestCase#TestCase(String)
         */
        public CompositeFTPParseTestFramework(String name)
        {
                super(name);
        }
  
        /**
         * @see FTPParseTestFramework#getGoodListing()
         */
        protected String[] getGoodListing()
        {
                return (getGoodListings()[0]);
        }
  
        /**
         * Method getBadListing.
         * Implementors must provide multiple listing that contains failures and
         * must force the composite parser to switch the FtpEntryParser
         *
         * @return String[]
         */
        protected abstract String[][] getBadListings();
  
        /**
         * Method getGoodListing.
         * Implementors must provide multiple listing that passes and
         * must force the composite parser to switch the FtpEntryParser
         *
         * @return String[]
         */
        protected abstract String[][] getGoodListings();
  
        /**
         * @see FTPParseTestFramework#getBadListing()
         */
        protected String[] getBadListing()
        {
                return (getBadListings()[0]);
        }
  
        /* (non-Javadoc)
         * @see 
org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
         */
        public void testConsistentListing() throws Exception
        {
                String goodsamples[][] = getGoodListings();
  
                for (int i = 0; i < goodsamples.length; i++)
                {
                        FTPFileEntryParser parser = getParser();
                        for (int j = 0; j < goodsamples[i].length; j++)
                        {
                                String test = goodsamples[i][j];
                                FTPFile f = parser.parseFTPEntry(test);
                                assertNotNull("Failed to parse " + test,
                                                f);
  
                                doAdditionalGoodTests(test, f);
                        }
                }
        }
  
        /* (non-Javadoc)
         * @see 
org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
         */
        public void testBadListing() throws Exception
        {
                String badsamples[][] = getBadListings();
  
                for (int i = 0; i < badsamples.length; i++)
                {
                        FTPFileEntryParser parser = getParser();
                        for (int j = 0; j < badsamples[i].length; j++)
                        {
                                String test = badsamples[i][j];
                                FTPFile f = parser.parseFTPEntry(test);
                                assertNull("Should have Failed to parse " + test,
                                                f);
  
                                doAdditionalBadTests(test, f);
                        }
                }
        }
  
        // even though all these listings are good using one parser
        // or the other, this tests that a parser that has succeeded
        // on one format will fail if another format is substituted.
        public void testInconsistentListing() throws Exception
        {
                String goodsamples[][] = getGoodListings();
  
                FTPFileEntryParser parser = getParser();
  
                for (int i = 0; i < goodsamples.length; i++)
                {
                        String test = goodsamples[i][0];
                        FTPFile f = parser.parseFTPEntry(test);
  
                        switch (i)
                        {
                        case 0:
                                assertNotNull("Failed to parse " + test, f);
                                break;
                        case 1:
                                assertNull("Should have failed to parse " + test, f);
                                break;
                        }
                }
        }
  }
  
  
  
  1.12      +5 -1      
jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
  
  Index: DefaultFTPFileEntryParserFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultFTPFileEntryParserFactory.java     6 Apr 2004 13:31:59 -0000       1.11
  +++ DefaultFTPFileEntryParserFactory.java     16 Apr 2004 01:52:24 -0000      1.12
  @@ -142,7 +142,11 @@
   
       public FTPFileEntryParser createOS400FTPEntryParser()
       {
  -        return new OS400FTPEntryParser();
  +        return new CompositeFileEntryParser(new FTPFileEntryParser[]
  +        {
  +            new OS400FTPEntryParser(),
  +            new UnixFTPEntryParser()
  +        });
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to