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