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 java.util.Calendar;
20  
21  import org.apache.commons.net.ftp.FTPFile;
22  import org.apache.commons.net.ftp.FTPFileEntryParser;
23  
24  /**
25   * @author <a href="mailto:rwinston@apache.org">Rory Winston</a>
26   * @version $Id: NetwareFTPEntryParserTest.java 1299238 2012-03-10 17:12:28Z sebb $
27   */
28  public class NetwareFTPEntryParserTest extends FTPParseTestFramework {
29  
30      private static final String[] badsamples = {
31          "a [-----F--] SCION_SYS                         512 Apr 13 23:52 SYS",
32              "d [----AF--]          0                        512 10-04-2001 _ADMIN"
33      };
34  
35      private static final String [] goodsamples = {
36          "d [-----F--] SCION_SYS                         512 Apr 13 23:52 SYS",
37          "d [----AF--]          0                        512 Feb 22 17:32 _ADMIN",
38          "d [-W---F--] SCION_VOL2                        512 Apr 13 23:12 VOL2",
39          "- [RWCEAFMS] rwinston                        19968 Mar 12 15:20 Executive Summary.doc",
40          "d [RWCEAFMS] rwinston                          512 Nov 24  2005 Favorites"
41      };
42  
43      /**
44       * @see junit.framework.TestCase#TestCase(String)
45       */
46      public NetwareFTPEntryParserTest(String name) {
47          super(name);
48      }
49  
50      /**
51       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
52       */
53      @Override
54      protected String[] getBadListing() {
55          return (badsamples);
56      }
57  
58      /**
59       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
60       */
61      @Override
62      protected String[] getGoodListing() {
63          return (goodsamples);
64      }
65  
66      /**
67       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
68       */
69      @Override
70      protected FTPFileEntryParser getParser() {
71          return (new NetwareFTPEntryParser());
72      }
73  
74      /**
75       * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
76       */
77      @Override
78      public void testParseFieldsOnDirectory() throws Exception {
79          String reply = "d [-W---F--] testUser                        512 Apr 13 23:12 testFile";
80          FTPFile f = getParser().parseFTPEntry(reply);
81  
82          assertNotNull("Could not parse file", f);
83          assertEquals("testFile", f.getName());
84          assertEquals(512L, f.getSize());
85          assertEquals("testUser", f.getUser());
86          assertTrue("Directory flag is not set!", f.isDirectory());
87  
88          Calendar cal = Calendar.getInstance();
89          cal.set(Calendar.MONTH, 3);
90          cal.set(Calendar.DAY_OF_MONTH, 13);
91          cal.set(Calendar.HOUR_OF_DAY, 23);
92          cal.set(Calendar.MINUTE, 12);
93          cal.set(Calendar.SECOND, 0);
94          cal.set(Calendar.MILLISECOND, 0);
95          cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR));
96  
97          assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp()
98                  .getTime()));
99  
100     }
101 
102 
103     /**
104      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
105      */
106     @Override
107     public void testParseFieldsOnFile() throws Exception {
108         String reply = "- [R-CEAFMS] rwinston                        19968 Mar 12 15:20 Document name with spaces.doc";
109 
110         FTPFile f = getParser().parseFTPEntry(reply);
111 
112         assertNotNull("Could not parse file", f);
113         assertEquals("Document name with spaces.doc", f.getName());
114         assertEquals(19968L, f.getSize());
115         assertEquals("rwinston", f.getUser());
116         assertTrue("File flag is not set!", f.isFile());
117 
118         assertTrue(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
119         assertFalse(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
120     }
121 
122 }