Source Code Cross Referenced for FTPClientConfigFunctionalTest.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » ftp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.ftp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net.ftp;
017:
018:        import junit.framework.TestCase;
019:        import java.io.IOException;
020:        import java.net.SocketException;
021:        import java.text.SimpleDateFormat;
022:        import java.util.Calendar;
023:        import java.util.Comparator;
024:        import java.util.Iterator;
025:        import java.util.TreeSet;
026:
027:        /*
028:         * This test was contributed in a different form by W. McDonald Buck
029:         * of Boulder, Colorado, to help fix some bugs with the FTPClientConfig
030:         * in a real world setting.  It is a perfect functional test for the
031:         * Time Zone functionality of FTPClientConfig.
032:         * 
033:         * A publicly accessible FTP server at the US National Oceanographic and
034:         * Atmospheric Adminstration houses a directory which contains 
035:         * 300 files, named sn.0000 to sn.0300. Every ten minutes or so 
036:         * the next file in sequence is rewritten with new data. Thus the directory 
037:         * contains observations for more than 24 hours of data.  Since the server
038:         * has its clock set to GMT this is an excellent functional test for any
039:         * machine in a different time zone. 
040:         * 
041:         * Noteworthy is the fact that the ftp routines in some web browsers don't 
042:         * work as well as this.  They can't, since they have no way of knowing the 
043:         * server's time zone.  Depending on the local machine's position relative 
044:         * to GMT and the time of day, the browsers may decide that a timestamp 
045:         * would be in the  future if given the current year, so they assume the 
046:         * year to be  last year.  This illustrates the value of FTPClientConfig's 
047:         * time zone functionality.
048:         */
049:
050:        public class FTPClientConfigFunctionalTest extends TestCase {
051:
052:            private FTPClient FTP = new FTPClient();
053:            private FTPClientConfig FTPConf;
054:
055:            /**
056:             * 
057:             */
058:            public FTPClientConfigFunctionalTest() {
059:                super ();
060:
061:            }
062:
063:            /* 
064:             * @throws java.lang.Exception
065:             */
066:            protected void setUp() throws Exception {
067:                super .setUp();
068:                FTPConf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
069:                FTPConf.setServerTimeZoneId("GMT");
070:                FTP.configure(FTPConf);
071:                try {
072:                    FTP.connect("tgftp.nws.noaa.gov");
073:                    FTP.login("anonymous", "testing@apache.org");
074:                    FTP
075:                            .changeWorkingDirectory("SL.us008001/DF.an/DC.sflnd/DS.metar");
076:                    FTP.enterLocalPassiveMode();
077:                } catch (SocketException e) {
078:                    e.printStackTrace();
079:                } catch (IOException e) {
080:                    e.printStackTrace();
081:                }
082:            }
083:
084:            /* 
085:             * @throws java.lang.Exception
086:             */
087:            protected void tearDown() throws Exception {
088:                FTP.disconnect();
089:                super .tearDown();
090:            }
091:
092:            /**
093:             * @param arg0
094:             */
095:            public FTPClientConfigFunctionalTest(String arg0) {
096:                super (arg0);
097:            }
098:
099:            private TreeSet getSortedList(FTPFile[] files) {
100:                // create a TreeSet which will sort each element
101:                // as it is added.
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(
108:                                f2.getTimestamp().getTime());
109:                    }
110:
111:                });
112:
113:                for (int i = 0; i < files.length; i++) {
114:                    // The directory contains a few additional files at the beginning
115:                    // which aren't in the series we want. The series we want consists
116:                    // of files named sn.dddd. This adjusts the file list to get rid 
117:                    // of the uninteresting ones. 
118:                    if (files[i].getName().startsWith("sn")) {
119:                        sorted.add(files[i]);
120:                    }
121:                }
122:                return sorted;
123:            }
124:
125:            public static void main(String[] args) {
126:                FTPClientConfigFunctionalTest F = new FTPClientConfigFunctionalTest();
127:            }
128:
129:            public void testTimeZoneFunctionality() throws Exception {
130:                java.util.Date now = new java.util.Date();
131:                FTPFile[] files = FTP.listFiles();
132:                TreeSet sorted = getSortedList(files);
133:                //SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm z" );
134:                FTPFile lastfile = null;
135:                FTPFile firstfile = null;
136:                for (Iterator it = sorted.iterator(); it.hasNext();) {
137:                    FTPFile this file = (FTPFile) it.next();
138:                    if (firstfile == null) {
139:                        firstfile = this file;
140:                    }
141:                    //System.out.println(sdf.format(thisfile.getTimestamp().getTime()) 
142:                    //        + " " +thisfile.getName());
143:                    if (lastfile != null) {
144:                        // verify that the list is sorted earliest to latest.
145:                        assertTrue(lastfile.getTimestamp().before(
146:                                this file.getTimestamp()));
147:                    }
148:                    lastfile = this file;
149:                }
150:
151:                // test that notwithstanding any time zone differences, the newest file
152:                // is older than now.
153:                assertTrue(lastfile.getTimestamp().getTime().before(now));
154:                Calendar first = firstfile.getTimestamp();
155:
156:                // test that the oldest is less than two days older than the newest 
157:                // and, in particular, that no files have been considered "future" 
158:                // by the parser and therefore been relegated to the same date a 
159:                // year ago.
160:                first.add(Calendar.DATE, 2);
161:                assertTrue(lastfile.getTimestamp().before(first));
162:
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.