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