/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.net.ftp.parser;

import java.util.Calendar;

import junit.framework.TestSuite;

import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPFileEntryParser;

/**
 * @author <a href="mailto:rwinston@apache.org">Rory Winston</a>
 * @version $Id$
 */
public class NetwareFTPEntryParserTest extends FTPParseTestFramework {

	private static final String[] badsamples = {
		"a [-----F--] SCION_SYS                         512 Apr 13 23:52 SYS",
    		"d [----AF--]          0                        512 10-04-2001 _ADMIN"
	};

	private static final String [] goodsamples = {
    	"d [-----F--] SCION_SYS                         512 Apr 13 23:52 SYS",
    	"d [----AF--]          0                        512 Feb 22 17:32 _ADMIN",
    	"d [-W---F--] SCION_VOL2                        512 Apr 13 23:12 VOL2",
    	"- [RWCEAFMS] rwinston                        19968 Mar 12 15:20 Executive Summary.doc",
    	"d [RWCEAFMS] rwinston                          512 Nov 24  2005 Favorites"
    };
	
	/**
	 * @see junit.framework.TestCase#TestCase(String)
	 */
	public NetwareFTPEntryParserTest(String name) {
		super(name);
	}

	/**
	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
	 */
	protected String[] getBadListing() {
		return (badsamples);
	}

	/**
	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing()
	 */
	protected String[] getGoodListing() {
		return (goodsamples);
	}

	/**
	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser()
	 */
	protected FTPFileEntryParser getParser() {
		return (new NetwareFTPEntryParser());
	}

	/**
	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory()
	 */
	
	public void testParseFieldsOnDirectory() throws Exception {
		String reply = "d [-W---F--] testUser                        512 Apr 13 23:12 testFile";
		FTPFile f = getParser().parseFTPEntry(reply);
		
		assertNotNull("Could not parse file", f);
		assertEquals("testFile", f.getName());
		assertEquals(512L, f.getSize());
		assertEquals("testUser", f.getUser());
		assertTrue("Directory flag is not set!", f.isDirectory());
		
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.MONTH, 3);
		cal.set(Calendar.DAY_OF_MONTH, 13);
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 12);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		
		assertEquals(df.format(cal.getTime()), df.format(f.getTimestamp()
				.getTime()));

	}
	
	
	/**
	 * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile()
	 */
	public void testParseFieldsOnFile() throws Exception {
		String reply = "- [R-CEAFMS] rwinston                        19968 Mar 12 15:20 Document name with spaces.doc";
		
		FTPFile f = getParser().parseFTPEntry(reply);
		
		assertNotNull("Could not parse file", f);
		assertEquals("Document name with spaces.doc", f.getName());
		assertEquals(19968L, f.getSize());
		assertEquals("rwinston", f.getUser());
		assertTrue("File flag is not set!", f.isFile());
		
		assertTrue(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
		assertFalse(f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
	}
	

	/**
	 * Method suite.
	 * @return TestSuite
	 */
	public static TestSuite suite() {
		return (new TestSuite(NetwareFTPEntryParserTest.class));
	}
	
	
}

@@ -4,21 +4,29 @@
 %0A * 
-Licensed to t
+Copyright 2001-2006 T
 he A
@@ -54,216 +54,25 @@
 tion
- (ASF) under one or more%0D%0A * contributor license agreements.  See the NOTICE file distributed with%0D%0A * this work for additional information regarding copyright ownership.%0D%0A * The ASF licenses this file to You
+%0D%0A *%0D%0A * Licensed
  und
@@ -105,20 +105,16 @@
 sion 2.0
-%0D%0A *
  (the %22L
@@ -122,16 +122,20 @@
 cense%22);
+%0D%0A *
  you may
@@ -178,20 +178,16 @@
 nce with
-%0D%0A *
  the Lic
@@ -191,17 +191,20 @@
 License.
- 
+%0D%0A *
  You may
@@ -3130,24 +3130,88 @@
 ECOND, 0);%0D%0A
+%09%09cal.set(Calendar.YEAR, f.getTimestamp().get(Calendar.YEAR));%0D%0A
 %09%09%0D%0A%09%09assert
@@ -4207,8 +4207,10 @@
 %0D%0A%09%0D%0A%7D%0D%0A
+%0D%0A

Fix calendar rollover bug