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.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.net.ftp.FTPFile;
23  import org.apache.commons.net.ftp.FTPFileEntryParser;
24  
25  /**
26   * Changed on August 31, 2006<br/>
27   * Test suite addapted to new MVSFTPEntryParser.java.
28   * @author <a href="mailto:henrik.sorensen@balcab.ch">Henrik Sorensen</a>
29   *
30   * Created on Apr 6, 2005<br/>
31   * @author <a href="mailto:wnoto@openfinance.com">William Noto</a>
32   * @version $Id: MVSFTPEntryParserTest.java 1299238 2012-03-10 17:12:28Z sebb $
33   */
34  public class MVSFTPEntryParserTest extends FTPParseTestFramework {
35  
36      private static final String[] goodsamplesDatasetList = { /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */
37              //  "Volume Unit    Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname",
38              "SAVE00 3390   2004/06/23  1    1  FB     128  6144  PS    INCOMING.RPTBM023.D061704",
39              "SAVE01 3390   2004/06/23  1    1  FB     128  6144  PO    INCOMING.RPTBM024.D061704",
40              "SAVE02 3390   2004/06/23  1    1  FB     128  6144  PO-E  INCOMING.RPTBM025.D061704",
41              "PSMLC1 3390   2005/04/04  1    1  VB   27994 27998  PS    file3.I",
42              "PSMLB9 3390   2005/04/04  1    1  VB   27994 27998  PS    file4.I.BU",
43              "PSMLB6 3390   2005/04/05  1    1  VB   27994 27998  PS    file3.I.BU",
44              "PSMLC6 3390   2005/04/05  1    1  VB   27994 27998  PS    file6.I",
45              "PSMLB7 3390   2005/04/04  1    1  VB   27994 27998  PS    file7.O",
46              "PSMLC6 3390   2005/04/05  1    1  VB   27994 27998  PS    file7.O.BU",
47              "FPFS49 3390   2004/06/23  1    1  FB     128  6144  PO-E  INCOMING.RPTBM026.D061704",
48              "FPFS41 3390   2004/06/23  1    1  FB     128  6144  PS    INCOMING.RPTBM056.D061704",
49              "FPFS25 3390   2004/06/23  1    1  FB     128  6144  PS    INCOMING.WTM204.D061704", };
50  
51      private static final String[] goodsamplesMemberList = {/* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */
52              "Name      VV.MM   Created       Changed      Size  Init   Mod   Id",
53              "SAVE03    01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001",
54              "SAVE04                                                              ", // no statistics
55              "TBSHELF1  01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001",
56              "TBSHELF2  01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001",
57              "TBSHELF3  01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001",
58              "TBSHELF4  01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001", };
59  
60      private static final String[] goodsamplesJES1List = { /* no header for JES1 (JES Interface level 1) */
61      /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */
62      "IBMUSER1  JOB01906  OUTPUT    3 Spool Files", };
63  
64      private static final String[] goodsamplesJES2List = { /* JES2 (JES Interface level 2) */
65              /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */
66              //"JOBNAME  JOBID    OWNER    STATUS CLASS",
67              "IBMUSER2 JOB01906 IBMUSER  OUTPUT A        RC=0000 3 spool files",
68              "IBMUSER  TSU01830 IBMUSER  OUTPUT TSU      ABEND=522 3 spool files", };
69  
70      private static final String[] badsamples = {
71              "MigratedP201.$FTXPBI1.$CF2ITB.$AAB0402.I",
72              "PSMLC133902005/04/041VB2799427998PSfile1.I", "file2.O", };
73  
74      /**
75       * @see junit.framework.TestCase#TestCase(String)
76       */
77      public MVSFTPEntryParserTest(String name) {
78          super(name);
79  
80      }
81  
82      /* (non-Javadoc)
83       * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings()
84       */
85      @Override
86      protected String[] getBadListing() {
87          return badsamples;
88      }
89  
90      /* (non-Javadoc)
91       * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings()
92       */
93      @Override
94      protected String[] getGoodListing() {
95          return goodsamplesDatasetList;
96      }
97  
98      protected List<String[]> getAllGoodListings() {
99          List<String[]> l = new ArrayList<String[]>();
100         l.add(goodsamplesDatasetList);
101         l.add(goodsamplesMemberList);
102         l.add(goodsamplesJES1List);
103         l.add(goodsamplesJES2List);
104 
105         return l;
106     }
107 
108 
109     /**
110      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
111      */
112     @Override
113     protected FTPFileEntryParser getParser() {
114         return new MVSFTPEntryParser();
115     }
116 
117     /*
118      * note the testGoodListing has to be the first test invoked, because
119      * some FTPFile entries are saved for the later tests
120      *
121      * (non-Javadoc)
122      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testGoodListing()
123      */
124     @Override
125     public void testGoodListing() throws Exception {
126         String[] goodsamples = getGoodListing();
127         MVSFTPEntryParser parser = new MVSFTPEntryParser();
128         parser.setType(MVSFTPEntryParser.FILE_LIST_TYPE);
129         parser.setRegex(MVSFTPEntryParser.FILE_LIST_REGEX);
130         for (String test : goodsamples) {
131             FTPFile f = parser.parseFTPEntry(test);
132             assertNotNull("Failed to parse " + test, f);
133             doAdditionalGoodTests(test, f);
134         }
135     }
136 
137     public void testMemberListing() throws Exception {
138         MVSFTPEntryParser parser = new MVSFTPEntryParser();
139         parser.setType(MVSFTPEntryParser.MEMBER_LIST_TYPE);
140         parser.setRegex(MVSFTPEntryParser.MEMBER_LIST_REGEX);
141         for (String test : goodsamplesMemberList) {
142             FTPFile f = parser.parseFTPEntry(test);
143             assertNotNull("Failed to parse " + test, f);
144             doAdditionalGoodTests(test, f);
145         }
146     }
147 
148     public void testJesLevel1Listing() {
149         MVSFTPEntryParser parser = new MVSFTPEntryParser();
150         parser.setType(MVSFTPEntryParser.JES_LEVEL_1_LIST_TYPE);
151         parser.setRegex(MVSFTPEntryParser.JES_LEVEL_1_LIST_REGEX);
152         for (String test : goodsamplesJES1List) {
153             FTPFile f = parser.parseFTPEntry(test);
154             assertNotNull("Failed to parse " + test, f);
155             doAdditionalGoodTests(test, f);
156         }
157     }
158 
159     public void testJesLevel2Listing() {
160         MVSFTPEntryParser parser = new MVSFTPEntryParser();
161         parser.setType(MVSFTPEntryParser.JES_LEVEL_2_LIST_TYPE);
162         parser.setRegex(MVSFTPEntryParser.JES_LEVEL_2_LIST_REGEX);
163         for (String test : goodsamplesJES2List) {
164             FTPFile f = parser.parseFTPEntry(test);
165             assertNotNull("Failed to parse " + test, f);
166             doAdditionalGoodTests(test, f);
167         }
168     }
169 
170     @Override
171     public void testParseFieldsOnDirectory() throws Exception {
172         MVSFTPEntryParser parser = new MVSFTPEntryParser();
173         parser.setType(MVSFTPEntryParser.FILE_LIST_TYPE);
174         parser.setRegex(MVSFTPEntryParser.FILE_LIST_REGEX);
175 
176         FTPFile file = parser
177                 .parseFTPEntry("SAVE01 3390   2004/06/23  1    1  FB     128  6144  PO    INCOMING.RPTBM024.D061704");
178         assertNotNull("Could not parse entry.", file);
179         assertTrue("Should have been a directory.", file.isDirectory());
180         assertEquals("INCOMING.RPTBM024.D061704", file.getName());
181 
182         file = parser
183                 .parseFTPEntry("SAVE02 3390   2004/06/23  1    1  FB     128  6144  PO-E  INCOMING.RPTBM025.D061704");
184         assertNotNull("Could not parse entry.", file);
185         assertTrue("Should have been a directory.", file.isDirectory());
186         assertEquals("INCOMING.RPTBM025.D061704", file.getName());
187 
188     }
189 
190     /* (non-Javadoc)
191      * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
192      */
193     @Override
194     public void testParseFieldsOnFile() throws Exception {
195         FTPFile file = null;
196 
197         MVSFTPEntryParser parser = new MVSFTPEntryParser();
198 
199         parser.setRegex(MVSFTPEntryParser.FILE_LIST_REGEX);
200         parser.setType(MVSFTPEntryParser.FILE_LIST_TYPE);
201 
202         file = parser.parseFTPEntry("SAVE00 3390   2004/06/23  1    1  FB     128  6144  PS    INCOMING.RPTBM023.D061704");
203         assertNotNull("Could not parse entry.", file);
204         assertTrue("Should have been a file.", file.isFile());
205         assertEquals("INCOMING.RPTBM023.D061704", file.getName());
206         assertNull("Timestamp should not have been set.", file.getTimestamp());
207 
208         parser.setType(MVSFTPEntryParser.MEMBER_LIST_TYPE);
209         parser.setRegex(MVSFTPEntryParser.MEMBER_LIST_REGEX);
210 
211         file = parser.parseFTPEntry("SAVE03    01.03 2002/09/12 2002/10/11 09:37    11    11     0 KIL001");
212         assertNotNull("Could not parse entry.", file);
213         assertTrue("Should have been a file.", file.isFile());
214         assertEquals("SAVE03", file.getName());
215         assertNotNull("Timestamp should have been set.", file.getTimestamp());
216 
217         file = parser.parseFTPEntry("SAVE04                                                              ");
218         assertNotNull("Could not parse entry.", file);
219         assertTrue("Should have been a file.", file.isFile());
220         assertEquals("SAVE04", file.getName());
221         assertNull("Timestamp should not have been set.", file.getTimestamp());
222 
223     }
224 }