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