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  
27  public class OS400FTPEntryParserAdditionalTest extends CompositeFTPParseTestFramework {
28      private static final String[][] badsamples = { { "QPGMR          135168 04/03/18 13:18:19 *FILE", "QPGMR          135168    03/24 13:18:19 *FILE",
29              "QPGMR          135168 04/03/18 30:06:29 *FILE", "QPGMR                 04/03/18 13:18:19 *FILE      RPGUNITC1.FILE",
30              "QPGMR          135168    03/24 13:18:19 *FILE      RPGUNITC1.FILE", "QPGMR          135168 04/03/18 30:06:29 *FILE      RPGUNITC1.FILE",
31              "QPGMR                                   *MEM       ", "QPGMR          135168 04/03/18 13:18:19 *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
32              "QPGMR          135168                   *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
33              "QPGMR                 04/03/18 13:18:19 *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
34              "QPGMR USR                               *MEM       RPGUNITC1.FILE/RUCALLTST.MBR" } };
35  
36      private static final String[][] goodsamples = { { "QPGMR                                   *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
37              "QPGMR        16347136 29.06.13 15:45:09 *FILE      RPGUNIT.SAVF" } };
38  
39      public OS400FTPEntryParserAdditionalTest(final String name) {
40          super(name);
41      }
42  
43      @Override
44      protected void doAdditionalGoodTests(final String test, final FTPFile f) {
45          if (test.startsWith("d")) {
46              assertEquals("directory.type", FTPFile.DIRECTORY_TYPE, f.getType());
47          }
48      }
49  
50      @Override
51      protected String[][] getBadListings() {
52          return badsamples;
53      }
54  
55      @Override
56      protected String[][] getGoodListings() {
57          return goodsamples;
58      }
59  
60      @Override
61      protected FTPFileEntryParser getParser() {
62          return new CompositeFileEntryParser(new FTPFileEntryParser[] { new OS400FTPEntryParser(), new UnixFTPEntryParser() });
63      }
64  
65      @Override
66      public void testDefaultPrecision() {
67          // Done in other class
68      }
69  
70      @Override
71      public void testParseFieldsOnDirectory() throws Exception {
72          final FTPFile f = getParser().parseFTPEntry("PEP             36864 04/03/24 14:06:34 *DIR       dir1/");
73          assertNotNull("Could not parse entry.", f);
74          assertTrue("Should have been a directory.", f.isDirectory());
75          assertEquals("PEP", f.getUser());
76          assertEquals("dir1", f.getName());
77          assertEquals(36864, f.getSize());
78  
79          final Calendar cal = Calendar.getInstance();
80          cal.set(Calendar.MONTH, Calendar.MARCH);
81  
82          cal.set(Calendar.YEAR, 2004);
83          cal.set(Calendar.DAY_OF_MONTH, 24);
84          cal.set(Calendar.HOUR_OF_DAY, 14);
85          cal.set(Calendar.MINUTE, 6);
86          cal.set(Calendar.SECOND, 34);
87  
88          assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
89      }
90  
91      @Override
92      public void testParseFieldsOnFile() throws Exception {
93          final FTPFile f = getParser().parseFTPEntry("PEP              5000000000 04/03/24 14:06:29 *STMF      build.xml");
94          assertNotNull("Could not parse entry.", f);
95          assertTrue("Should have been a file.", f.isFile());
96          assertEquals("PEP", f.getUser());
97          assertEquals("build.xml", f.getName());
98          assertEquals(5000000000L, f.getSize());
99  
100         final Calendar cal = Calendar.getInstance();
101 
102         cal.set(Calendar.DAY_OF_MONTH, 24);
103         cal.set(Calendar.MONTH, Calendar.MARCH);
104         cal.set(Calendar.YEAR, 2004);
105         cal.set(Calendar.HOUR_OF_DAY, 14);
106         cal.set(Calendar.MINUTE, 6);
107         cal.set(Calendar.SECOND, 29);
108         assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
109     }
110 
111     @Override
112     public void testRecentPrecision() {
113         // Done in other class
114     }
115 }