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.assertNotNull;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import java.util.Calendar;
24  
25  import org.apache.commons.net.ftp.FTPFile;
26  import org.apache.commons.net.ftp.FTPFileEntryParser;
27  import org.junit.jupiter.api.Test;
28  
29  /**
30   */
31  class OS400FTPEntryParserAdditionalTest extends CompositeFTPParseTestFramework {
32      private static final String[][] badsamples = { { "QPGMR          135168 04/03/18 13:18:19 *FILE", "QPGMR          135168    03/24 13:18:19 *FILE",
33              "QPGMR          135168 04/03/18 30:06:29 *FILE", "QPGMR                 04/03/18 13:18:19 *FILE      RPGUNITC1.FILE",
34              "QPGMR          135168    03/24 13:18:19 *FILE      RPGUNITC1.FILE", "QPGMR          135168 04/03/18 30:06:29 *FILE      RPGUNITC1.FILE",
35              "QPGMR                                   *MEM       ", "QPGMR          135168 04/03/18 13:18:19 *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
36              "QPGMR          135168                   *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
37              "QPGMR                 04/03/18 13:18:19 *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
38              "QPGMR USR                               *MEM       RPGUNITC1.FILE/RUCALLTST.MBR" } };
39  
40      private static final String[][] goodsamples = { { "QPGMR                                   *MEM       RPGUNITC1.FILE/RUCALLTST.MBR",
41              "QPGMR        16347136 29.06.13 15:45:09 *FILE      RPGUNIT.SAVF" } };
42  
43      @Override
44      protected void doAdditionalGoodTests(final String test, final FTPFile f) {
45          if (test.startsWith("d")) {
46              assertEquals(FTPFile.DIRECTORY_TYPE, f.getType(), "directory.type");
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      @Test
67      void testDefaultPrecision() {
68          // Done in other class
69      }
70  
71      @Override
72      @Test
73      void testParseFieldsOnDirectory() throws Exception {
74          final FTPFile f = getParser().parseFTPEntry("PEP             36864 04/03/24 14:06:34 *DIR       dir1/");
75          assertNotNull(f, "Could not parse entry.");
76          assertTrue(f.isDirectory(), "Should have been a directory.");
77          assertEquals("PEP", f.getUser());
78          assertEquals("dir1", f.getName());
79          assertEquals(36864, f.getSize());
80  
81          final Calendar cal = Calendar.getInstance();
82          cal.set(Calendar.MONTH, Calendar.MARCH);
83  
84          cal.set(Calendar.YEAR, 2004);
85          cal.set(Calendar.DAY_OF_MONTH, 24);
86          cal.set(Calendar.HOUR_OF_DAY, 14);
87          cal.set(Calendar.MINUTE, 6);
88          cal.set(Calendar.SECOND, 34);
89  
90          assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
91      }
92  
93      @Override
94      @Test
95      void testParseFieldsOnFile() throws Exception {
96          final FTPFile f = getParser().parseFTPEntry("PEP              5000000000 04/03/24 14:06:29 *STMF      build.xml");
97          assertNotNull(f, "Could not parse entry.");
98          assertTrue(f.isFile(), "Should have been a file.");
99          assertEquals("PEP", f.getUser());
100         assertEquals("build.xml", f.getName());
101         assertEquals(5000000000L, f.getSize());
102 
103         final Calendar cal = Calendar.getInstance();
104 
105         cal.set(Calendar.DAY_OF_MONTH, 24);
106         cal.set(Calendar.MONTH, Calendar.MARCH);
107         cal.set(Calendar.YEAR, 2004);
108         cal.set(Calendar.HOUR_OF_DAY, 14);
109         cal.set(Calendar.MINUTE, 6);
110         cal.set(Calendar.SECOND, 29);
111         assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp().getTime()));
112     }
113 
114     @Override
115     @Test
116     void testRecentPrecision() {
117         // Done in other class
118     }
119 }