1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package gnu.hylafax.util;
27
28 import gnu.hylafax.Client;
29 import gnu.hylafax.HylaFAXClient;
30
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.FileOutputStream;
34 import java.io.RandomAccessFile;
35 import java.util.Vector;
36
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40 /***
41 * @author John Yeary <jyeary@javanetwork.net>
42 * @version 1.0
43 *
44 * <p>
45 * This class was created to move the test out of the HylaFAXClient class.
46 * </p>
47 * <p>
48 * TODO A better test framework needs to be put into place.
49 * </p>
50 */
51 public class HylaFAXClientTest extends HylaFAXClient {
52
53 private final static Log log = LogFactory.getLog(Client.class);
54
55 /*** Creates a new instance of HylaFAXClientTest */
56 public HylaFAXClientTest() {
57
58 }
59
60 /***
61 * Run some basic tests.
62 *
63 * @param Arguments
64 * an array of command-line-argument Strings
65 */
66 public static void main(String Arguments[]) {
67 HylaFAXClient c = new HylaFAXClient();
68
69 try {
70 c.open("localhost");
71 c.noop();
72 c.setPassive(true);
73 c.user("fax");
74
75
76
77
78
79 c.type(TYPE_IMAGE);
80
81 System.out.println("current directory is: " + c.pwd());
82
83 c.cwd("docq");
84
85 System.out.println("current directory is: " + c.pwd());
86
87 c.cdup();
88 System.out.println("current directory is: " + c.pwd());
89
90
91 System.out.println("idle timer set to " + c.idle() + " seconds.");
92 c.idle(1800);
93 System.out.println("idle timer set to " + c.idle() + " seconds.");
94
95 System.out.println("job format: " + c.jobfmt());
96 c.jobfmt("%-4j");
97 System.out.println("job format: " + c.jobfmt());
98
99
100 c.stru(STRU_FILE);
101
102 c.stru(STRU_TIFF);
103
104 c.stru(STRU_FILE);
105
106
107 {
108 String filename = "test.ps";
109 FileInputStream file = new FileInputStream(filename);
110
111 String f = c.putTemporary(file);
112 System.out.println("filename= " + f);
113
114
115 long local_size, remote_size;
116 local_size = (new RandomAccessFile(filename, "r").length());
117 remote_size = c.size(f);
118 System.out.println(filename + " local size is " + local_size);
119 System.out.println(f + " remote size is " + remote_size);
120
121
122 FileOutputStream out_file = new FileOutputStream(filename
123 + ".retr");
124 c.get(f, out_file);
125 local_size = (new RandomAccessFile(filename + ".retr", "r")
126 .length());
127 System.out.println(filename + ".retr size is " + local_size);
128
129
130 FileOutputStream zip_file = new FileOutputStream(filename
131 + ".gz");
132 c.mode(MODE_ZLIB);
133 c.get(f, zip_file);
134 local_size = (new RandomAccessFile(filename + ".gz", "r")
135 .length());
136 System.out.println(filename + ".gz size is " + local_size);
137 c.mode(MODE_STREAM);
138
139 }
140
141
142
143 {
144 Vector files;
145 int counter;
146
147
148 files = c.getList();
149 for (counter = 0; counter < files.size(); counter++) {
150 System.out.println((String) files.elementAt(counter));
151 }
152
153
154 files = c.getList("/tmp");
155 for (counter = 0; counter < files.size(); counter++) {
156 System.out.println((String) files.elementAt(counter));
157 }
158
159
160 c.mode(MODE_ZLIB);
161 files = c.getList("/tmp");
162 for (counter = 0; counter < files.size(); counter++) {
163 System.out.println((String) files.elementAt(counter));
164 }
165 c.mode(MODE_STREAM);
166
167 try {
168
169 c.getList("/joey-joe-joe-jr.shabba-do");
170
171
172
173 System.out.println("ERROR: file not found was expected");
174 } catch (FileNotFoundException fnfe) {
175
176 System.out.println("GOOD: file not found, as expected");
177 }
178
179
180 files = c.getList();
181 for (counter = 0; counter < files.size(); counter++) {
182 System.out.println((String) files.elementAt(counter));
183 }
184 }
185
186
187
188 {
189 Vector files;
190 int counter;
191
192
193 files = c.getNameList("/tmp");
194
195 for (counter = 0; counter < files.size(); counter++) {
196 System.out.println((String) files.elementAt(counter));
197 }
198
199
200 files = c.getNameList("/tmp");
201
202 for (counter = 0; counter < files.size(); counter++) {
203 System.out.println((String) files.elementAt(counter));
204 }
205
206
207 c.mode(MODE_ZLIB);
208 files = c.getNameList("/tmp");
209
210 for (counter = 0; counter < files.size(); counter++) {
211 System.out.println((String) files.elementAt(counter));
212 }
213
214 c.mode(MODE_STREAM);
215
216
217 files = c.getNameList();
218
219 for (counter = 0; counter < files.size(); counter++) {
220 System.out.println((String) files.elementAt(counter));
221 }
222
223 }
224
225
226
227 String system = c.syst();
228 System.out.println("system type: " + system + ".");
229
230 c.noop();
231
232
233 {
234
235 Vector status = c.stat();
236 int counter;
237 for (counter = 0; counter < status.size(); counter++) {
238 System.out.println(status.elementAt(counter));
239 }
240
241
242 status = c.stat("docq");
243 for (counter = 0; counter < status.size(); counter++) {
244 System.out.println(status.elementAt(counter));
245 }
246
247
248 try {
249 status = c.stat("joey-joe-joe-junior-shabba-do");
250 for (counter = 0; counter < status.size(); counter++) {
251 System.out.println(status.elementAt(counter));
252 }
253 } catch (FileNotFoundException fnfe) {
254 System.out
255 .println("GOOD: file not found. this is what we expected");
256 }
257 }
258
259 c.noop();
260
261 c.quit();
262
263 } catch (Exception e) {
264 log.error(e.getMessage(), e);
265 }
266
267 System.out.println("main: end");
268 }
269
270 }