1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.net.ftp;
18
19 import junit.framework.TestCase;
20 import java.io.IOException;
21 import java.net.SocketException;
22 import java.text.SimpleDateFormat;
23 import java.util.Calendar;
24 import java.util.Comparator;
25 import java.util.Iterator;
26 import java.util.TreeSet;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class FTPClientConfigFunctionalTest extends TestCase {
52
53 private FTPClient FTP = new FTPClient();
54 private FTPClientConfig FTPConf;
55
56
57 /**
58 *
59 */
60 public FTPClientConfigFunctionalTest() {
61 super();
62
63 }
64
65
66
67
68 protected void setUp() throws Exception {
69 super.setUp();
70 FTPConf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
71 FTPConf.setServerTimeZoneId("GMT");
72 FTP.configure(FTPConf);
73 try {
74 FTP.connect("tgftp.nws.noaa.gov");
75 FTP.login("anonymous","testing@apache.org");
76 FTP.changeWorkingDirectory("SL.us008001/DF.an/DC.sflnd/DS.metar");
77 FTP.enterLocalPassiveMode();
78 } catch (SocketException e) {
79 e.printStackTrace();
80 } catch (IOException e) {
81 e.printStackTrace();
82 }
83 }
84
85
86
87 protected void tearDown() throws Exception {
88 FTP.disconnect();
89 super.tearDown();
90 }
91 /**
92 * @param arg0
93 */
94 public FTPClientConfigFunctionalTest(String arg0) {
95 super(arg0);
96 }
97
98
99 private TreeSet getSortedList(FTPFile[] files) {
100
101
102 TreeSet sorted = new TreeSet(new Comparator() {
103
104 public int compare(Object o1, Object o2) {
105 FTPFile f1 = (FTPFile) o1;
106 FTPFile f2 = (FTPFile) o2;
107 return f1.getTimestamp().getTime().compareTo(f2.getTimestamp().getTime());
108 }
109
110 });
111
112
113 for (int i=0; i < files.length; i++) {
114
115
116
117
118 if (files[i].getName().startsWith("sn")) {
119 sorted.add(files[i]);
120 }
121 }
122 return sorted;
123 }
124
125
126 public static void main(String[] args) {
127 FTPClientConfigFunctionalTest F = new FTPClientConfigFunctionalTest();
128 }
129
130 public void testTimeZoneFunctionality() throws Exception {
131 java.util.Date now = new java.util.Date();
132 FTPFile[] files = FTP.listFiles();
133 TreeSet sorted = getSortedList(files);
134
135 FTPFile lastfile = null;
136 FTPFile firstfile = null;
137 for (Iterator it = sorted.iterator(); it.hasNext();) {
138 FTPFile thisfile = (FTPFile) it.next();
139 if (firstfile == null) {
140 firstfile = thisfile;
141 }
142
143
144 if (lastfile != null) {
145
146 assertTrue(lastfile.getTimestamp()
147 .before(thisfile.getTimestamp()));
148 }
149 lastfile = thisfile;
150 }
151
152
153
154 assertTrue(lastfile.getTimestamp().getTime().before(now));
155 Calendar first = firstfile.getTimestamp();
156
157
158
159
160
161 first.add(Calendar.DATE, 2);
162 assertTrue(lastfile.getTimestamp().before(first));
163
164 }
165 }
166
167
168
169