Methods Summary |
---|
private java.util.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(java.lang.String[] args)
FTPClientConfigFunctionalTest F = new FTPClientConfigFunctionalTest();
|
protected void | setUp()
super.setUp();
FTPConf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
FTPConf.setServerTimeZoneId("GMT");
FTP.configure(FTPConf);
try {
FTP.connect("tgftp.nws.noaa.gov");
FTP.login("anonymous","testing@apache.org");
FTP.changeWorkingDirectory("SL.us008001/DF.an/DC.sflnd/DS.metar");
FTP.enterLocalPassiveMode();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
|
protected void | tearDown()
FTP.disconnect();
super.tearDown();
|
public void | testTimeZoneFunctionality()
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));
|