Source code: org/finj/test/FTPClientTest.java
1 package org.finj.test;
2
3 import java.io.IOException;
4 import java.util.ResourceBundle;
5
6 import org.finj.FTPClient;
7
8 /**
9 * The configuration used by the FTPClientTest is embodied in
10 * a <code>.properties</code> file.
11 * If no file is provided, then the default configuration is used :
12 *
13 * <pre># connection settings
14 * host = localhost
15 * port = 21
16 *
17 * # login settings
18 * user = finj
19 * pass = ,finj.test
20 *
21 * # directory settings
22 * path = /tmp
23 * temp = finj
24 * file = test.txt</pre>
25 *
26 * Any of those values can be overriden in a file named
27 * <code>FTPClientTestConfiguration.properties</code>
28 * placed in <code>CLASSPATH</code> <b>before</b> <code>finj</code>
29 * binaries, and using the same syntax.
30 *
31 * Copyright (C)
32 *
33 * This library is free software; you can redistribute it and/or
34 * modify it under the terms of the GNU Lesser General Public
35 * License as published by the Free Software Foundation; either
36 * version 2.1 of the License, or (at your option) any later version.
37 *
38 * This library is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41 * Lesser General Public License for more details.
42 *
43 * You should have received a copy of the GNU Lesser General Public
44 * License along with this library; if not, write to the Free Software
45 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
46 *
47 * @author Javier Iglesias -- jiglesias@users.sourceforge.net
48 * @version $Id: FTPClientTest.java,v 1.5 2003/10/22 08:26:26 jiglesia Exp $
49 */
50 public class FTPClientTest extends FTPClient {
51
52 private static final String CONFIGURATION_FILE = "org/finj/test/resources/TestConfiguration";
53
54 private static final String HOST_PARAM = "host";
55 private static final String PORT_PARAM = "port";
56 private static final String USER_PARAM = "user";
57 private static final String PASS_PARAM = "pass";
58 private static final String PATH_PARAM = "path";
59 private static final String TEMP_PARAM = "temp";
60 private static final String FILE_PARAM = "file";
61
62 private ResourceBundle config = null;
63
64 private String host = "localhost";
65 private int port = 21;
66 private String user = "anonymous";
67 private char[] pass = new String("finj@localhost").toCharArray();
68 private String path = "/tmp";
69 private String temp = "finj-test";
70 private String file = "test.txt";
71
72 /**
73 *
74 *
75 * @since v1.0.2
76 */
77 public FTPClientTest ( ) throws IOException {
78 config = ResourceBundle.getBundle(CONFIGURATION_FILE);
79 if ( config == null ) {
80 throw new IOException("Could not load configuration file (" + CONFIGURATION_FILE + ")");
81 }
82
83 host = config.getString(HOST_PARAM);
84 port = Integer.parseInt(config.getString(PORT_PARAM));
85 user = config.getString(USER_PARAM);
86 pass = config.getString(PASS_PARAM).toCharArray();
87 }
88
89 /**
90 *
91 *
92 * @since v1.0.2
93 */
94 public void open ( ) throws IOException {
95 super.open(host, port);
96 login(user, pass);
97 }
98
99 /**
100 *
101 *
102 * @since v1.0.2
103 */
104 public void makeDirectory ( ) throws IOException {
105 setWorkingDirectory();
106 super.makeDirectory(temp);
107 }
108
109 /**
110 *
111 *
112 * @since v1.0.2
113 */
114 public void removeDirectory ( ) throws IOException {
115 setWorkingDirectory();
116 super.removeDirectory(temp);
117 }
118
119 /**
120 *
121 *
122 * @since v1.0.2
123 */
124 public void setWorkingDirectory ( ) throws IOException {
125 super.setWorkingDirectory(path);
126 }
127
128 /**
129 *
130 *
131 * @since v1.0.2
132 */
133 public String[] getFileNames ( boolean passive ) throws IOException {
134 setWorkingDirectory();
135 return super.getFileNames(passive);
136 }
137
138 /**
139 *
140 *
141 * @since v1.0.2
142 */
143 public String[] getServerStatus ( ) throws IOException {
144 return super.getServerStatus();
145 }
146 }