001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.net.ftp.parser; 018 019 import java.util.ArrayList; 020 import java.util.List; 021 022 import junit.framework.TestSuite; 023 024 import org.apache.commons.net.ftp.FTPFile; 025 import org.apache.commons.net.ftp.FTPFileEntryParser; 026 027 /** 028 * Changed on August 31, 2006<br/> 029 * Test suite addapted to new MVSFTPEntryParser.java. 030 * @author <a href="mailto:henrik.sorensen@balcab.ch">Henrik Sorensen</a> 031 * 032 * Created on Apr 6, 2005<br/> 033 * @author <a href="mailto:wnoto@openfinance.com">William Noto</a> 034 * @version $Id: MVSFTPEntryParserTest.java,v 1.16 2005/01/02 03:17:50 scohen Exp $ 035 */ 036 public class MVSFTPEntryParserTest extends FTPParseTestFramework { 037 038 private static final String[] goodsamplesDatasetList = { /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ 039 // "Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname", 040 "SAVE00 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM023.D061704", 041 "SAVE01 3390 2004/06/23 1 1 FB 128 6144 PO INCOMING.RPTBM024.D061704", 042 "SAVE02 3390 2004/06/23 1 1 FB 128 6144 PO-E INCOMING.RPTBM025.D061704", 043 "PSMLC1 3390 2005/04/04 1 1 VB 27994 27998 PS file3.I", 044 "PSMLB9 3390 2005/04/04 1 1 VB 27994 27998 PS file4.I.BU", 045 "PSMLB6 3390 2005/04/05 1 1 VB 27994 27998 PS file3.I.BU", 046 "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file6.I", 047 "PSMLB7 3390 2005/04/04 1 1 VB 27994 27998 PS file7.O", 048 "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file7.O.BU", 049 "FPFS49 3390 2004/06/23 1 1 FB 128 6144 PO-E INCOMING.RPTBM026.D061704", 050 "FPFS41 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM056.D061704", 051 "FPFS25 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.WTM204.D061704", }; 052 053 private static final String[] goodsamplesMemberList = {/* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ 054 "Name VV.MM Created Changed Size Init Mod Id", 055 "SAVE03 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001", 056 "SAVE04 ", // no statistics 057 "TBSHELF1 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001", 058 "TBSHELF2 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001", 059 "TBSHELF3 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001", 060 "TBSHELF4 01.03 2002/09/12 2002/10/11 09:37 11 11 0 KIL001", }; 061 062 private static final String[] goodsamplesJES1List = { /* no header for JES1 (JES Interface level 1) */ 063 /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ 064 "IBMUSER1 JOB01906 OUTPUT 3 Spool Files", }; 065 066 private static final String[] goodsamplesJES2List = { /* JES2 (JES Interface level 2) */ 067 /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ 068 //"JOBNAME JOBID OWNER STATUS CLASS", 069 "IBMUSER2 JOB01906 IBMUSER OUTPUT A RC=0000 3 spool files", 070 "IBMUSER TSU01830 IBMUSER OUTPUT TSU ABEND=522 3 spool files", }; 071 072 private static final String[] badsamples = { 073 "MigratedP201.$FTXPBI1.$CF2ITB.$AAB0402.I", 074 "PSMLC133902005/04/041VB2799427998PSfile1.I", "file2.O", }; 075 076 /** 077 * @see junit.framework.TestCase#TestCase(String) 078 */ 079 public MVSFTPEntryParserTest(String name) { 080 super(name); 081 082 } 083 084 /* (non-Javadoc) 085 * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getBadListings() 086 */ 087 @Override 088 protected String[] getBadListing() { 089 return badsamples; 090 } 091 092 /* (non-Javadoc) 093 * @see org.apache.commons.net.ftp.parser.CompositeFTPParseTestFramework#getGoodListings() 094 */ 095 @Override 096 protected String[] getGoodListing() { 097 return goodsamplesDatasetList; 098 } 099 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 }