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.Calendar; 020 021 import junit.framework.TestSuite; 022 023 import org.apache.commons.net.ftp.FTPFile; 024 import org.apache.commons.net.ftp.FTPFileEntryParser; 025 026 /** 027 * @author <a href="mailto:rwinston@apache.org">Rory Winston</a> 028 * @version $Id: NetwareFTPEntryParserTest.java 492109 2007-01-03 11:24:57Z rwinston $ 029 */ 030 public class NetwareFTPEntryParserTest extends FTPParseTestFramework { 031 032 private static final String[] badsamples = { 033 "a [-----F--] SCION_SYS 512 Apr 13 23:52 SYS", 034 "d [----AF--] 0 512 10-04-2001 _ADMIN" 035 }; 036 037 private static final String [] goodsamples = { 038 "d [-----F--] SCION_SYS 512 Apr 13 23:52 SYS", 039 "d [----AF--] 0 512 Feb 22 17:32 _ADMIN", 040 "d [-W---F--] SCION_VOL2 512 Apr 13 23:12 VOL2", 041 "- [RWCEAFMS] rwinston 19968 Mar 12 15:20 Executive Summary.doc", 042 "d [RWCEAFMS] rwinston 512 Nov 24 2005 Favorites" 043 }; 044 045 /** 046 * @see junit.framework.TestCase#TestCase(String) 047 */ 048 public NetwareFTPEntryParserTest(String name) { 049 super(name); 050 } 051 052 /** 053 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing() 054 */ 055 @Override 056 protected String[] getBadListing() { 057 return (badsamples); 058 } 059 060 /** 061 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing() 062 */ 063 @Override 064 protected String[] getGoodListing() { 065 return (goodsamples); 066 } 067 068 /** 069 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser() 070 */ 071 @Override 072 protected FTPFileEntryParser getParser() { 073 return (new NetwareFTPEntryParser()); 074 } 075 076 /** 077 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory() 078 */ 079 @Override 080 public void testParseFieldsOnDirectory() throws Exception { 081 String reply = "d [-W---F--] testUser 512 Apr 13 23:12 testFile"; 082 FTPFile f = getParser().parseFTPEntry(reply); 083 084 assertNotNull("Could not parse file", f); 085 assertEquals("testFile", f.getName()); 086 assertEquals(512L, f.getSize()); 087 assertEquals("testUser", f.getUser()); 088 assertTrue("Directory flag is not set!", f.isDirectory()); 089 090 Calendar cal = Calendar.getInstance(); 091 cal.set(Calendar.MONTH, 3); 092 cal.set(Calendar.DAY_OF_MONTH, 13); 093 cal.set(Calendar.HOUR_OF_DAY, 23); 094 cal.set(Calendar.MINUTE, 12); 095 cal.set(Calendar.SECOND, 0); 096 cal.set(Calendar.MILLISECOND, 0); 097 cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR)); 098 099 assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp() 100 .getTime())); 101 102 } 103 104 105 /** 106 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile() 107 */ 108 @Override 109 public void testParseFieldsOnFile() throws Exception { 110 String reply = "- [R-CEAFMS] rwinston 19968 Mar 12 15:20 Document name with spaces.doc"; 111 112 FTPFile f = getParser().parseFTPEntry(reply); 113 114 assertNotNull("Could not parse file", f); 115 assertEquals("Document name with spaces.doc", f.getName()); 116 assertEquals(19968L, f.getSize()); 117 assertEquals("rwinston", f.getUser()); 118 assertTrue("File flag is not set!", f.isFile()); 119 120 assertTrue(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); 121 assertFalse(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); 122 } 123 124 125 /** 126 * Method suite. 127 * @return TestSuite 128 */ 129 public static TestSuite suite() { 130 return (new TestSuite(NetwareFTPEntryParserTest.class)); 131 } 132 133 134 }