Author: scohen Date: Sat Feb 5 04:56:14 2005 New Revision: 151489 URL: http://svn.apache.org/viewcvs?view=rev&rev=151489 Log: Add new functional test submitted by W. McDonald Buck accessing a server at NOAA to test timezone functionality.
Added: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/FTPClientConfigFunctionalTest.java Modified: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/AllTests.java Modified: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/AllTests.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/AllTests.java?view=diff&r1=151488&r2=151489 ============================================================================== --- jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/AllTests.java (original) +++ jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/AllTests.java Sat Feb 5 04:56:14 2005 @@ -28,6 +28,7 @@ //$JUnit-BEGIN$ suite.addTest(ListingFunctionalTest.suite()); suite.addTestSuite(FTPClientConfigTest.class); + suite.addTestSuite(FTPClientConfigFunctionalTest.class); //$JUnit-END$ return suite; } Added: jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/FTPClientConfigFunctionalTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/FTPClientConfigFunctionalTest.java?view=auto&rev=151489 ============================================================================== --- jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/FTPClientConfigFunctionalTest.java (added) +++ jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/FTPClientConfigFunctionalTest.java Sat Feb 5 04:56:14 2005 @@ -0,0 +1,161 @@ +/* + * Copyright 2005 The Apache Software Foundation + * + * Licensed 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; + +import junit.framework.TestCase; +import java.io.IOException; +import java.net.SocketException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Comparator; +import java.util.Iterator; +import java.util.TimeZone; +import java.util.TreeSet; + +/* + * This test was contributed in a different form by W. McDonald Buck + * of Boulder, Colorado, to help fix some bugs with the FTPClientConfig + * in a real world setting. It is a perfect functional test for the + * Time Zone functionality of FTPClientConfig. + * + * A publicly accessible FTP server at the US National Oceanographic and + * Atmospheric Adminstration houses a directory which contains + * 300 files, named sn.0000 to sn.0300. Every ten minutes or so + * the next file in sequence is rewritten with new data. Thus the directory + * contains observations for more than 24 hours of data. Since the server + * has its clock set to GMT this is an excellent functional test for any + * machine in a different time zone. + */ + +public class FTPClientConfigFunctionalTest extends TestCase { + + private FTPClient FTP = new FTPClient(); + private FTPClientConfig FTPConf; + + + /** + * + */ + public FTPClientConfigFunctionalTest() { + super(); + + } + + /* + * @throws java.lang.Exception + */ + protected void setUp() throws Exception { + super.setUp(); + FTPConf = new FTPClientConfig(FTPClientConfig.SYST_UNIX); + FTPConf.setServerTimeZoneId("GMT"); + FTP.configure(FTPConf); + try { + FTP.connect("tgftp.nws.noaa.gov"); + FTP.login("anonymous","[EMAIL PROTECTED]"); + FTP.changeWorkingDirectory("SL.us008001/DF.an/DC.sflnd/DS.metar"); + FTP.enterLocalPassiveMode(); + } catch (SocketException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /* + * @throws java.lang.Exception + */ + protected void tearDown() throws Exception { + FTP.disconnect(); + super.tearDown(); + } + /** + * @param arg0 + */ + public FTPClientConfigFunctionalTest(String arg0) { + super(arg0); + } + + + private TreeSet getSortedList(FTPFile[] files) { + // create a TreeSet which will sort each element + // as it is added. + TreeSet sorted = new TreeSet(new Comparator() { + + public int compare(Object o1, Object o2) { + FTPFile f1 = (FTPFile) o1; + FTPFile f2 = (FTPFile) o2; + return f1.getTimestamp().getTime().compareTo(f2.getTimestamp().getTime()); + } + + }); + + + for (int i=0; i < files.length; i++) { + // The directory contains a few additional files at the beginning + // which aren't in the series we want. The series we want consists + // of files named sn.dddd. This adjusts the file list to get rid + // of the uninteresting ones. + if (files[i].getName().startsWith("sn")) { + sorted.add(files[i]); + } + } + return sorted; + } + + + public static void main(String[] args) { + FTPClientConfigFunctionalTest F = new FTPClientConfigFunctionalTest(); + } + + public void testTimeZoneFunctionality() throws Exception { + java.util.Date now = new java.util.Date(); + FTPFile[] files = FTP.listFiles(); + TreeSet sorted = getSortedList(files); + //SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm z" ); + FTPFile lastfile = null; + FTPFile firstfile = null; + for (Iterator it = sorted.iterator(); it.hasNext();) { + FTPFile thisfile = (FTPFile) it.next(); + if (firstfile == null) { + firstfile = thisfile; + } + //System.out.println(sdf.format(thisfile.getTimestamp().getTime()) + // + " " +thisfile.getName()); + if (lastfile != null) { + // verify that the list is sorted earliest to latest. + assertTrue(lastfile.getTimestamp() + .before(thisfile.getTimestamp())); + } + lastfile = thisfile; + } + + // test that notwithstanding any time zone differences, the newest file + // is older than now. + assertTrue(lastfile.getTimestamp().getTime().before(now); + Calendar first = firstfile.getTimestamp(); + + // test that the oldest is less than two days older than the newest + // and, in particular, that no files have been considered "future" + // by the parser and therefore been relegated to the same date a + // year ago. + first.add(Calendar.DATE, 2); + assertTrue(lastfile.getTimestamp().before(first)); + + } +} + + + + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]