commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bre...@apache.org
Subject cvs commit: jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser FTPParseTestFramework.java NTFTPEntryParserTest.java OS2FTPEntryParserTest.java UnixFTPEntryParserTest.java VMSFTPEntryParserTest.java
Date Tue, 06 Aug 2002 20:32:05 GMT
brekke      2002/08/06 13:32:05

  Modified:    net/src/java/org/apache/commons/net/ftp/ftp2/parser
                        UnixFTPEntryParser.java VMSFTPEntryParser.java
               net/src/test/org/apache/commons/net/ftp/ftp2/parser
                        FTPParseTestFramework.java
                        NTFTPEntryParserTest.java
                        OS2FTPEntryParserTest.java
                        UnixFTPEntryParserTest.java
                        VMSFTPEntryParserTest.java
  Log:
  o Fixed problem with the UnixParser's regular expression and determining
  file types.  It wasn't working when a - was used.
  
  o Fixed a problem with the VMSParser not properly getting the group name.
  
  o Changed around the tests for the parsers.  The abstract test case now
  actually contains tests that all parsers must pass.  There are abstract
  methods that children must implement to give the parent listing data.
  
  o Added tests for all fields parsed to the Unix and VMS parsers.  VMS still
  doesn't parse out the permissions at this time.
  
  Revision  Changes    Path
  1.4       +13 -12    jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParser.java
  
  Index: UnixFTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UnixFTPEntryParser.java	3 May 2002 14:52:30 -0000	1.3
  +++ UnixFTPEntryParser.java	6 Aug 2002 20:32:04 -0000	1.4
  @@ -71,16 +71,16 @@
       private static final String MONTHS =
           "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
       private static final String REGEX =
  -        "([bcdlf])"
  -        + "(((r|-)(w|-)(x|-))((r|-)(w|-)(x|-))((r|-)(w|-)(x|-)))\\s*"
  -        + "(\\d*)\\s*"
  -        + "(\\S*)\\s*"
  -        + "(\\S*)\\s*"
  -        + "(\\d*)\\s*"
  -        + MONTHS + "\\s*"
  -        + "((?:[012]\\d*)|(?:3[01]))\\s*"
  +        "([bcdlf-])"
  +        + "(((r|-)(w|-)(x|-))((r|-)(w|-)(x|-))((r|-)(w|-)(x|-)))\\s+"
  +        + "(\\d+)\\s+"
  +        + "(\\S+)\\s+"
  +        + "(\\S+)\\s+"
  +        + "(\\d+)\\s+"
  +        + MONTHS + "\\s+"
  +        + "((?:[012]\\d*)|(?:3[01]))\\s+"
           + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s"
  -        + "(\\S*)(\\s*.*)";
  +        + "(\\S+)(\\s*.*)";
   
       
       /**
  @@ -129,7 +129,6 @@
               String name = group(25);
               String endtoken = group(26);
   
  -
               switch (typeStr.charAt(0))
               {
               case 'd':
  @@ -145,6 +144,9 @@
               default:
                   type = FTPFile.FILE_TYPE;
               }
  +
  +            file.setType(type);
  +           
               int g = 4;
               for (int access = 0; access < 3; access++, g += 4)
               {
  @@ -251,7 +253,6 @@
               }
               return file;
           }
  -
           return null;
       }
   }
  
  
  
  1.5       +2 -2      jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParser.java
  
  Index: VMSFTPEntryParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParser.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- VMSFTPEntryParser.java	6 Aug 2002 15:23:37 -0000	1.4
  +++ VMSFTPEntryParser.java	6 Aug 2002 20:32:04 -0000	1.5
  @@ -127,7 +127,7 @@
           MONTHS +
           "-([0-9]{4})\\s*" +
           "((?:[01]\\d)|(?:2[0-3])):([012345]\\d):([012345]\\d)\\s*" +
  -        "(\\[[0-9$A-Za-z_]+),([0-9$a-zA-Z_]+)\\]\\s*" +
  +        "\\[([0-9$A-Za-z_]+),([0-9$a-zA-Z_]+)\\]\\s*" +
           "(\\([a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*,[a-zA-Z]*\\))";
   
   
  
  
  
  1.2       +33 -21    jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/FTPParseTestFramework.java
  
  Index: FTPParseTestFramework.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/FTPParseTestFramework.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FTPParseTestFramework.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ FTPParseTestFramework.java	6 Aug 2002 20:32:04 -0000	1.2
  @@ -53,48 +53,60 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   import junit.framework.TestCase;
  +
   import org.apache.commons.net.ftp.FTPFile;
   import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
   
   /**
  - * FTPParseTestFramework.java
  - * This provides a basic framework for pass-fail testing of
  - * sample FTP directory strings in a particular format.
  - *
    * @author <a href="mailto:stevecoh1@attbi.com">Steve Cohen</a>
    * @version $Id$
    */
  -
   public abstract class FTPParseTestFramework extends TestCase
   {
  -    FTPFileEntryParser parser;
   
  -    public FTPParseTestFramework (String name, FTPFileEntryParser parser)
  +    private FTPFileEntryParser parser = null;
  +
  +    public FTPParseTestFramework(String name)
       {
           super(name);
  -        this.parser = parser;
       }
   
  -    protected void _testPositive(String[] goodsamples) throws Exception
  +    public void testBadListing() throws Exception
       {
  -        for (int i = 0; i < goodsamples.length; i++)
  +
  +        String[] badsamples = getBadListing();
  +        for (int i = 0; i < badsamples.length; i++)
           {
  -            String test = goodsamples[i];
  -            FTPFile f = this.parser.parseFTPEntry(test);
  -            assertNotNull( "Failed to parse " + test, f);
  +
  +            String test = badsamples[i];
  +            FTPFile f = parser.parseFTPEntry(test);
  +            assertNull("Should have Failed to parse " + test, 
  +                       f);
           }
       }
   
  -    protected void _testNegative(String[] badsamples) throws Exception
  +    public void testGoodListing() throws Exception
       {
  -        for (int i = 0; i < badsamples.length; i++)
  +
  +        String[] goodsamples = getGoodListing();
  +        for (int i = 0; i < goodsamples.length; i++)
           {
  -            String test = badsamples[i];
  -            FTPFile f = this.parser.parseFTPEntry(test);
  -            assertNull( "Should have Failed to parse " + test, f);
  +
  +            String test = goodsamples[i];
  +            FTPFile f = parser.parseFTPEntry(test);
  +            assertNotNull("Failed to parse " + test, 
  +                          f);
           }
       }
   
  -}
  +    protected abstract String[] getBadListing();
  +    protected abstract String[] getGoodListing();
  +    protected abstract FTPFileEntryParser getParser();
  +
  +    protected void setUp() throws Exception
  +    {
  +        super.setUp();
  +        parser = getParser();
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.2       +20 -9     jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/NTFTPEntryParserTest.java
  
  Index: NTFTPEntryParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/NTFTPEntryParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NTFTPEntryParserTest.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ NTFTPEntryParserTest.java	6 Aug 2002 20:32:04 -0000	1.2
  @@ -54,10 +54,11 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
  +
  +import junit.framework.TestSuite;
  +
   /**
  - * NTFTPEntryParserTest.java
  - * Tests the NTFTPEntryParser
  - *
    * @author <a href="mailto:scohen@stevecoh1@attbi.com">Steve Cohen</a>
    * @versionn $Id$
    */
  @@ -89,16 +90,26 @@
   
       public NTFTPEntryParserTest (String name)
       {
  -        super(name, new NTFTPEntryParser());
  +        super(name);
       }
   
  -    public void testPositive() throws Exception
  +    protected String[] getGoodListing()
       {
  -        _testPositive(goodsamples);
  +        return(goodsamples);
       }
  -    public void testNegative() throws Exception
  +    
  +    protected String[] getBadListing()
       {
  -        _testNegative(badsamples);
  +        return(badsamples);
  +    }
   
  +    protected FTPFileEntryParser getParser()
  +    {
  +        return(new NTFTPEntryParser());
  +    }
  +    
  +    public static TestSuite suite()
  +    {
  +        return(new TestSuite(NTFTPEntryParserTest.class));
       }
   }
  
  
  
  1.2       +22 -10    jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/OS2FTPEntryParserTest.java
  
  Index: OS2FTPEntryParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/OS2FTPEntryParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OS2FTPEntryParserTest.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ OS2FTPEntryParserTest.java	6 Aug 2002 20:32:04 -0000	1.2
  @@ -54,10 +54,11 @@
    * <http://www.apache.org/>.
    */
   
  +import junit.framework.TestSuite;
  +
  +import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
  +
   /**
  - * OS2FTPEntryParserTest.java
  - * Tests the OS2FTPEntryParser
  - *
    * @author <a href="mailto:scohen@stevecoh1@attbi.com">Steve Cohen</a>
    * @version $Id$
    */
  @@ -94,16 +95,27 @@
   
       public OS2FTPEntryParserTest (String name)
       {
  -        super(name, new OS2FTPEntryParser());
  +        super(name);
       }
   
  -    public void testPositive() throws Exception
  +    protected String[] getGoodListing()
       {
  -        _testPositive(goodsamples);
  +        return(goodsamples);
       }
  -    public void testNegative() throws Exception
  +    
  +    protected String[] getBadListing()
       {
  -        _testNegative(badsamples);
  -
  +        return(badsamples);
  +    }
  +    
  +    protected FTPFileEntryParser getParser()
  +    {
  +        return(new OS2FTPEntryParser());
  +    }
  +    
  +    public static TestSuite suite()
  +    {
  +        return(new TestSuite(OS2FTPEntryParserTest.class));
       }
  +    
   }
  
  
  
  1.2       +132 -37   jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParserTest.java
  
  Index: UnixFTPEntryParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/UnixFTPEntryParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnixFTPEntryParserTest.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ UnixFTPEntryParserTest.java	6 Aug 2002 20:32:05 -0000	1.2
  @@ -54,56 +54,151 @@
    * <http://www.apache.org/>.
    */
   
  +import junit.framework.TestSuite;
  +
  +import org.apache.commons.net.ftp.FTPFile;
  +import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
  +
   /**
  - * UnixFTPEntryParserTest.java
  - * Tests the UnixFTPEntryParser
  - *
    * @author <a href="mailto:scohen@stevecoh1@attbi.com">Steve Cohen</a>
    * @versionn $Id$
    */
   public class UnixFTPEntryParserTest extends FTPParseTestFramework
   {
  -    private static final String[] goodsamples = {
  -                "drwxr-xr-x   2 root     root         4096 Mar  2 15:13 zxbox",
  -                "drwxr-xr-x   2 root     root         4096 Aug 24  2001 zxjdbc",
  -                "drwxr-xr-x   2 root     root         4096 Jan  4 00:03 zziplib",
  -                "drwxr-xr-x   2 root     99           4096 Feb 23  2001 zzplayer",
  -                "drwxr-xr-x   2 root     root         4096 Aug  6  2001 zztpp",
  -                "-rw-r--r--   1 14       staff       80284 Aug 22  2000 zxJDBC-1.2.3.tar.gz",
  -                "-rw-r--r--   1 14       staff      119926 Aug 22  2000 zxJDBC-1.2.3.zip",
  -                "-rw-r--r--   1 ftp      nogroup     83853 Jan 22  2001 zxJDBC-1.2.4.tar.gz",
  -                "-rw-r--r--   1 ftp      nogroup    126552 Jan 22  2001 zxJDBC-1.2.4.zip",
  -                "-rw-r--r--   1 root     root       111325 Apr 27  2001 zxJDBC-2.0.1b1.tar.gz",
  -                "-rw-r--r--   1 root     root       190144 Apr 27  2001 zxJDBC-2.0.1b1.zip"
  -            };
  -    private static final String[] badsamples = {
  -                "zrwxr-xr-x   2 root     root         4096 Mar  2 15:13 zxbox",
  -                "dxrwr-xr-x   2 root     root         4096 Aug 24  2001 zxjdbc",
  -                "drwxr-xr-x   2 root     root         4096 Jam  4 00:03 zziplib",
  -                "drwxr-xr-x   2 root     99           4096 Feb 23 30:01 zzplayer",
  -                "drwxr-xr-x   2 root     root         4096 Aug 36  2001 zztpp",
  -                "-rw-r--r--   1 14       staff       80284 Aug 22  zxJDBC-1.2.3.tar.gz",
  -                "-rw-r--r--   1 14       staff      119:26 Aug 22  2000 zxJDBC-1.2.3.zip",
  -                "-rw-r--r--   1 ftp      no group    83853 Jan 22  2001 zxJDBC-1.2.4.tar.gz",
  -                "-rw-r--r--   1ftp       nogroup    126552 Jan 22  2001 zxJDBC-1.2.4.zip",
  -                "-rw-r--r--   1 root     root       111325 Apr -7 18:79 zxJDBC-2.0.1b1.tar.gz",
  -            };
  -
   
  +    private static final String[] badsamples = 
  +    {
  +        "zrwxr-xr-x   2 root     root         4096 Mar  2 15:13 zxbox", 
  +        "dxrwr-xr-x   2 root     root         4096 Aug 24  2001 zxjdbc", 
  +        "drwxr-xr-x   2 root     root         4096 Jam  4 00:03 zziplib", 
  +        "drwxr-xr-x   2 root     99           4096 Feb 23 30:01 zzplayer", 
  +        "drwxr-xr-x   2 root     root         4096 Aug 36  2001 zztpp", 
  +        "-rw-r--r--   1 14       staff       80284 Aug 22  zxJDBC-1.2.3.tar.gz", 
  +        "-rw-r--r--   1 14       staff      119:26 Aug 22  2000 zxJDBC-1.2.3.zip", 
  +        "-rw-r--r--   1 ftp      no group    83853 Jan 22  2001 zxJDBC-1.2.4.tar.gz", 
  +        "-rw-r--r--   1ftp       nogroup    126552 Jan 22  2001 zxJDBC-1.2.4.zip", 
  +        "-rw-r--r--   1 root     root       111325 Apr -7 18:79 zxJDBC-2.0.1b1.tar.gz"
  +    };
   
  +    private static final String[] goodsamples = 
  +    {
  +        "-rwxr-xr-x   2 root     root         4096 Mar  2 15:13 zxbox", 
  +        "drwxr-xr-x   2 root     root         4096 Aug 24  2001 zxjdbc", 
  +        "drwxr-xr-x   2 root     root         4096 Jan  4 00:03 zziplib", 
  +        "drwxr-xr-x   2 root     99           4096 Feb 23  2001 zzplayer", 
  +        "drwxr-xr-x   2 root     root         4096 Aug  6  2001 zztpp", 
  +        "lrw-r--r--   1 14       14          80284 Aug 22  2000 zxJDBC-1.2.3.tar.gz", 
  +        "srw-r--r--   1 14       staff      119926 Aug 22  2000 zxJDBC-1.2.3.zip", 
  +        "crw-r--r--   1 ftp      nogroup     83853 Jan 22  2001 zxJDBC-1.2.4.tar.gz", 
  +        "brw-r--r--   1 ftp      nogroup    126552 Jan 22  2001 zxJDBC-1.2.4.zip", 
  +        "-rw-r--r--   1 root     root       111325 Apr 27  2001 zxJDBC-2.0.1b1.tar.gz",

  +        "-rw-r--r--   1 root     root       190144 Apr 27  2001 zxJDBC-2.0.1b1.zip",
  +        "-rwxr-xr-x   2 500      500           166 Nov  2  2001 73131-testtes1.afp",
  +        "-rw-r--r--   1 500      500           166 Nov  9  2001 73131-testtes1.AFP",
  +        "-rw-r--r--   1 500      500           166 Nov 12  2001 73131-testtes2.afp",
  +        "-rw-r--r--   1 500      500           166 Nov 12  2001 73131-testtes2.AFP",  
   
  +        "-rw-r--r--   1 500      500       2040000 Aug  5 07:35 testRemoteUPCopyNIX",
  +        "-rw-r--r--   1 500      500       2040000 Aug  5 07:31 testRemoteUPDCopyNIX",
  +        "-rw-r--r--   1 500      500       2040000 Aug  5 07:31 testRemoteUPVCopyNIX" 
     
  +    };
   
  -    public UnixFTPEntryParserTest (String name)
  -    {
  -        super(name, new UnixFTPEntryParser());
  +    public UnixFTPEntryParserTest(String name)
  +    {
  +        super(name);
       }
   
  -    public void testPositive() throws Exception
  +    protected String[] getBadListing()
  +    {
  +        return(badsamples);
  +    }
  +    
  +    protected String[] getGoodListing()
       {
  -        _testPositive(goodsamples);
  +        return(goodsamples);
       }
  -    public void testNegative() throws Exception
  +    
  +    protected FTPFileEntryParser getParser() 
       {
  -        _testNegative(badsamples);
  +        return(new UnixFTPEntryParser());
  +    }
  +    
  +    public void testParseFieldsOnDirectory() throws Exception
  +    {
  +        FTPFile f = getParser().parseFTPEntry("drwxr-xr-x   2 user     group         4096
Mar  2 15:13 zxbox");
  +        assertNotNull("Could not parse entry.", 
  +                      f);
  +        assertTrue("Should have been a directory.", 
  +                   f.isDirectory());       
  +        checkPermissions(f);
  +        assertEquals(2, 
  +                     f.getHardLinkCount());
  +        assertEquals("user", 
  +                     f.getUser());
  +        assertEquals("group", 
  +                     f.getGroup());
  +        assertEquals("zxbox", 
  +                     f.getName());
  +        assertEquals(4096, 
  +                     f.getSize());
  +        assertEquals("Sat Mar 02 15:13:00 CST 2002", 
  +                     f.getTimestamp().getTime().toString());
  +    }
  +
  +    private void checkPermissions(FTPFile f)
  +    {
  +        assertTrue("Should have user read permission.", 
  +                   f.hasPermission(FTPFile.USER_ACCESS, 
  +                                   FTPFile.READ_PERMISSION));
  +        assertTrue("Should have user write permission.", 
  +                   f.hasPermission(FTPFile.USER_ACCESS, 
  +                                   FTPFile.WRITE_PERMISSION));
  +        assertTrue("Should have user execute permission.", 
  +                   f.hasPermission(FTPFile.USER_ACCESS, 
  +                                   FTPFile.EXECUTE_PERMISSION));
  +        assertTrue("Should have group read permission.", 
  +                   f.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                   FTPFile.READ_PERMISSION));
  +        assertTrue("Should NOT have group write permission.", 
  +                   !f.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                    FTPFile.WRITE_PERMISSION));
  +        assertTrue("Should have group execute permission.", 
  +                   f.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                   FTPFile.EXECUTE_PERMISSION));
  +        assertTrue("Should have world read permission.", 
  +                   f.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                   FTPFile.READ_PERMISSION));
  +        assertTrue("Should NOT have world write permission.", 
  +                   !f.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                    FTPFile.WRITE_PERMISSION));
  +        assertTrue("Should have world execute permission.", 
  +                   f.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                   FTPFile.EXECUTE_PERMISSION));
  +    }
   
  +    public void testParseFieldsOnFile() throws Exception
  +    {
  +        FTPFile f = getParser().parseFTPEntry("-rwxr-xr-x   2 user     group         4096
Mar  2 15:13 zxbox");
  +        assertNotNull("Could not parse entry.", 
  +                      f);
  +        assertTrue("Should have been a file.", 
  +                   f.isFile());
  +        checkPermissions(f);
  +        assertEquals(2, 
  +                     f.getHardLinkCount());
  +        assertEquals("user", 
  +                     f.getUser());
  +        assertEquals("group", 
  +                     f.getGroup());
  +        assertEquals("zxbox", 
  +                     f.getName());
  +        assertEquals(4096, 
  +                     f.getSize());
  +        assertEquals("Sat Mar 02 15:13:00 CST 2002", 
  +                     f.getTimestamp().getTime().toString());
  +    }
  +    
  +    public static TestSuite suite()
  +    {
  +        return(new TestSuite(UnixFTPEntryParserTest.class));
       }
   }
  
  
  
  1.2       +116 -31   jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParserTest.java
  
  Index: VMSFTPEntryParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/test/org/apache/commons/net/ftp/ftp2/parser/VMSFTPEntryParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VMSFTPEntryParserTest.java	29 Apr 2002 03:55:32 -0000	1.1
  +++ VMSFTPEntryParserTest.java	6 Aug 2002 20:32:05 -0000	1.2
  @@ -53,52 +53,137 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  + 
  +import junit.framework.TestSuite;
  +
  +import org.apache.commons.net.ftp.FTPFile;
  +import org.apache.commons.net.ftp.ftp2.FTPFileEntryParser;
   
   /**
  - * VMSFTPEntryParserTest.java
  - * Tests the VMSFTPEntryParser
  - *
    * @author <a href="mailto:scohen@stevecoh1@attbi.com">Steve Cohen</a>
    * @version $Id$
    */
   public class VMSFTPEntryParserTest extends FTPParseTestFramework
   {
  +    private static final String[] badsamples = 
  +    {
   
  -    private static final String [] goodsamples = {
  -                "1-JUN.LIS;1              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -                "1-JUN.LIS;2              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,)",
  -                "1-JUN.LIS;2              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,)",
  -                "DATA.DIR;1               1/9           2-JUN-1998 07:32:04  [GROUP,OWNER]
   (,RWED,RWED,RE)",
  -                "120196.TXT;1           118/126        14-APR-1997 12:45:27  [GROUP,OWNER]
   (RWED,,RWED,RE)",
  -                "30CHARBAR.TXT;1         11/18          2-JUN-1998 08:38:42  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -                "A.;2                    18/18          1-JUL-1998 08:43:20  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -                "AA.;2                  152/153        13-FEB-1997 08:13:43  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -            };
  +        "1-JUN.LIS;1              9/9           2-jun-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,RE)",

  +        "1-JUN.LIS;2              9/9           JUN-2-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,)",

  +        "1-JUN.LIS;2              a/9           2-JUN-98 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,)",

  +        "DATA.DIR; 1              1/9           2-JUN-1998 07:32:04  [GROUP,OWNER]    (,RWED,RWED,RE)",

  +        "120196.TXT;1           118/126        14-APR-1997 12:45:27 PM  [GROUP,OWNER] 
  (RWED,,RWED,RE)", 
  +        "30CHARBAR.TXT;1         11/18          2-JUN-1998 08:38:42  [GROUP-1,OWNER]  
 (RWED,RWED,RWED,RE)", 
  +        "A.;2                    18/18          1-JUL-1998 08:43:20  [GROUP,OWNER]    (RWED2,RWED,RWED,RE)",

  +        "AA.;2                  152/153        13-FED-1997 08:13:43  [GROUP,OWNER]    (RWED,RWED,RWED,RE)"
  +    };
  +    
  +    private static final String[] goodsamples = 
  +    {
   
  -    private static final String [] badsamples = {
  -                "1-JUN.LIS;1              9/9           2-jun-1998 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -                "1-JUN.LIS;2              9/9           JUN-2-1998 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,)",
  -                "1-JUN.LIS;2              a/9           2-JUN-98 07:32:04  [GROUP,OWNER]
   (RWED,RWED,RWED,)",
  -                "DATA.DIR; 1              1/9           2-JUN-1998 07:32:04  [GROUP,OWNER]
   (,RWED,RWED,RE)",
  -                "120196.TXT;1           118/126        14-APR-1997 12:45:27 PM  [GROUP,OWNER]
   (RWED,,RWED,RE)",
  -                "30CHARBAR.TXT;1         11/18          2-JUN-1998 08:38:42  [GROUP-1,OWNER]
   (RWED,RWED,RWED,RE)",
  -                "A.;2                    18/18          1-JUL-1998 08:43:20  [GROUP,OWNER]
   (RWED2,RWED,RWED,RE)",
  -                "AA.;2                  152/153        13-FED-1997 08:13:43  [GROUP,OWNER]
   (RWED,RWED,RWED,RE)",
  -            };
  +        "1-JUN.LIS;1              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,RE)",

  +        "1-JUN.LIS;2              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,)",

  +        "1-JUN.LIS;2              9/9           2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,)",

  +        "DATA.DIR;1               1/9           2-JUN-1998 07:32:04  [GROUP,OWNER]    (,RWED,RWED,RE)",

  +        "120196.TXT;1           118/126        14-APR-1997 12:45:27  [GROUP,OWNER]    (RWED,,RWED,RE)",

  +        "30CHARBAR.TXT;1         11/18          2-JUN-1998 08:38:42  [GROUP,OWNER]    (RWED,RWED,RWED,RE)",

  +        "A.;2                    18/18          1-JUL-1998 08:43:20  [GROUP,OWNER]    (RWED,RWED,RWED,RE)",

  +        "AA.;2                  152/153        13-FEB-1997 08:13:43  [GROUP,OWNER]    (RWED,RWED,RWED,RE)"
  +    };
   
  +    public VMSFTPEntryParserTest(String name)
  +    {
  +        super(name);
  +    }
   
  -    public VMSFTPEntryParserTest (String name)
  +    public void testParseFieldsOnDirecotry()
       {
  -        super(name, new VMSFTPEntryParser());
  +
  +        FTPFile dir = getParser().parseFTPEntry("DATA.DIR;1               1/9         
 2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,RE)");
  +        assertTrue("Should be a directory.", 
  +                   dir.isDirectory());
  +        assertEquals("DATA.DIR", 
  +                     dir.getName());
  +        assertEquals(512, 
  +                     dir.getSize());
  +        assertEquals("Tue Jun 02 07:32:04 CDT 1998", 
  +                     dir.getTimestamp().getTime().toString());
  +        assertEquals("GROUP", 
  +                     dir.getGroup());
  +        assertEquals("OWNER", 
  +                     dir.getUser());
  +        checkPermisions(dir);
       }
   
  -    public void testPositive() throws Exception
  +    public void testParseFieldsOnFile()
       {
  -        _testPositive(goodsamples);
  +        FTPFile file = getParser().parseFTPEntry("1-JUN.LIS;1              9/9        
  2-JUN-1998 07:32:04  [GROUP,OWNER]    (RWED,RWED,RWED,RE)");
  +        assertTrue("Should be a file.", 
  +                   file.isFile());
  +        assertEquals("1-JUN.LIS", 
  +                     file.getName());
  +        assertEquals(9 * 512, 
  +                     file.getSize());
  +        assertEquals("Tue Jun 02 07:32:04 CDT 1998", 
  +                     file.getTimestamp().getTime().toString());
  +        assertEquals("GROUP", 
  +                     file.getGroup());
  +        assertEquals("OWNER", 
  +                     file.getUser());
  +        checkPermisions(file);
       }
  -    public void testNegative() throws Exception
  +
  +    protected String[] getBadListing()
       {
  -        _testNegative(badsamples);
   
  +        return (badsamples);
       }
  -}
  +
  +    protected String[] getGoodListing()
  +    {
  +
  +        return (goodsamples);
  +    }
  +
  +    protected FTPFileEntryParser getParser()
  +    {
  +
  +        return (new VMSFTPEntryParser());
  +    }
  +
  +    private void checkPermisions(FTPFile dir)
  +    {
  +        assertTrue("Owner should not have read permission.", 
  +                   !dir.hasPermission(FTPFile.USER_ACCESS, 
  +                                      FTPFile.READ_PERMISSION));
  +        assertTrue("Owner should not have write permission.", 
  +                   !dir.hasPermission(FTPFile.USER_ACCESS, 
  +                                      FTPFile.WRITE_PERMISSION));
  +        assertTrue("Owner should not have execute permission.", 
  +                   !dir.hasPermission(FTPFile.USER_ACCESS, 
  +                                      FTPFile.EXECUTE_PERMISSION));
  +        assertTrue("Group should not have read permission.", 
  +                   !dir.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                      FTPFile.READ_PERMISSION));
  +        assertTrue("Group should not have write permission.", 
  +                   !dir.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                      FTPFile.WRITE_PERMISSION));
  +        assertTrue("Group should not have execute permission.", 
  +                   !dir.hasPermission(FTPFile.GROUP_ACCESS, 
  +                                      FTPFile.EXECUTE_PERMISSION));
  +        assertTrue("World should not have read permission.", 
  +                   !dir.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                      FTPFile.READ_PERMISSION));
  +        assertTrue("World should not have write permission.", 
  +                   !dir.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                      FTPFile.WRITE_PERMISSION));
  +        assertTrue("World should not have execute permission.", 
  +                   !dir.hasPermission(FTPFile.WORLD_ACCESS, 
  +                                      FTPFile.EXECUTE_PERMISSION));
  +    }
  +    
  +    public static TestSuite suite()
  +    {
  +        return(new TestSuite(VMSFTPEntryParserTest.class));
  +    }   
  +}
  \ No newline at end of file
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message