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