|
1 // |
|
2 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 // All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Nokia Corporation - initial contribution. |
|
11 // |
|
12 // Contributors: |
|
13 // |
|
14 // Description: |
|
15 // |
|
16 |
|
17 import java.io.File; |
|
18 import java.io.FileInputStream; |
|
19 import java.io.FileOutputStream; |
|
20 import java.io.IOException; |
|
21 import java.io.OutputStream; |
|
22 import java.util.regex.Matcher; |
|
23 import java.util.regex.Pattern; |
|
24 |
|
25 import junit.framework.TestCase; |
|
26 |
|
27 import org.apache.commons.net.ftp.FTP; |
|
28 import org.apache.commons.net.ftp.FTPClient; |
|
29 import org.apache.commons.net.ftp.FTPFile; |
|
30 import org.apache.commons.net.ftp.FTPReply; |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 /** |
|
36 * @author JavierM |
|
37 * |
|
38 */ |
|
39 public abstract class FTPTest extends TestCase { |
|
40 |
|
41 /* (non-Javadoc) |
|
42 * @see junit.framework.TestCase#setUp() |
|
43 */ |
|
44 FTPClient ftpClient = new FTPClient(); |
|
45 |
|
46 protected void setUp() throws Exception { |
|
47 super.setUp(); |
|
48 |
|
49 String address = System.getProperty("address"); |
|
50 |
|
51 ftpClient.connect(/*"10.16.160.35"*/address); |
|
52 ftpClient.user("me"); |
|
53 ftpClient.pass("friend"); |
|
54 |
|
55 ftpClient.setBufferSize(1460*10); |
|
56 |
|
57 setPassive(); |
|
58 } |
|
59 |
|
60 protected void setPassive() |
|
61 { |
|
62 ftpClient.enterLocalActiveMode(); |
|
63 } |
|
64 |
|
65 /* (non-Javadoc) |
|
66 * @see junit.framework.TestCase#tearDown() |
|
67 */ |
|
68 protected void tearDown() throws Exception { |
|
69 super.tearDown(); |
|
70 |
|
71 ftpClient.logout(); |
|
72 ftpClient.disconnect(); |
|
73 } |
|
74 |
|
75 |
|
76 // public void testUploadFileInSmallChunks() throws IOException |
|
77 // { |
|
78 // |
|
79 // byte b[] = new byte[1]; |
|
80 // |
|
81 // String sentence = new String(b);//"El veloz murciélago hind?comía feliz cardillo y kiwi\r\n"; |
|
82 // int times = 10000; |
|
83 // |
|
84 // assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
85 // |
|
86 // //BINARY |
|
87 // |
|
88 // assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
89 // |
|
90 // OutputStream out = ftpClient.storeFileStream("test.txt"); |
|
91 // assertNotNull(out); |
|
92 // |
|
93 // for (int i = 0; i < times; i++) { |
|
94 // out.write(sentence.getBytes()); |
|
95 // out.flush(); |
|
96 // System.out.print("."); |
|
97 // } |
|
98 // |
|
99 // out.close(); |
|
100 // assertTrue(ftpClient.completePendingCommand()); |
|
101 // |
|
102 // assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/test.txt"))); |
|
103 // assertEquals(times*sentence.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
104 // |
|
105 // ftpClient.deleteFile("/C/test.txt"); |
|
106 // |
|
107 // //ASCII |
|
108 // |
|
109 // assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
110 // |
|
111 // out = ftpClient.storeFileStream("test.txt"); |
|
112 // assertNotNull(out); |
|
113 // |
|
114 // for (int i = 0; i < times; i++) { |
|
115 // out.write(sentence.getBytes()); |
|
116 // } |
|
117 // |
|
118 // out.close(); |
|
119 // assertTrue(ftpClient.completePendingCommand()); |
|
120 // |
|
121 // assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/test.txt"))); |
|
122 // assertEquals(times*sentence.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
123 // |
|
124 // ftpClient.deleteFile("/C/test.txt"); |
|
125 // |
|
126 // } |
|
127 |
|
128 |
|
129 public void testSyst() throws IOException |
|
130 { |
|
131 String name = ftpClient.getSystemName(); |
|
132 assertEquals(name,"UNIX Type: L8"); |
|
133 |
|
134 } |
|
135 |
|
136 |
|
137 |
|
138 public void testListDrives() throws IOException{ |
|
139 |
|
140 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
141 FTPFile[] drives = ftpClient.listFiles(); |
|
142 |
|
143 assertNotNull(drives); |
|
144 |
|
145 for (int i = 0; i < drives.length; i++) { |
|
146 |
|
147 String driveName = drives[i].getName(); |
|
148 |
|
149 assertTrue(driveName.length()==1 && |
|
150 driveName.charAt(0) >= 'A' && |
|
151 driveName.charAt(0) <= 'Z'); |
|
152 } |
|
153 |
|
154 String[] names = ftpClient.listNames(); |
|
155 |
|
156 assertNotNull(names); |
|
157 |
|
158 for (int i = 0; i < drives.length; i++) { |
|
159 |
|
160 String driveName = names[i]; |
|
161 |
|
162 assertTrue(driveName.length()==1 && |
|
163 driveName.charAt(0) >= 'A' && |
|
164 driveName.charAt(0) <= 'Z'); |
|
165 } |
|
166 |
|
167 |
|
168 } |
|
169 |
|
170 public void testListFiles() throws IOException{ |
|
171 |
|
172 FTPFile[] files; |
|
173 |
|
174 //UNIX parseable contents on C |
|
175 |
|
176 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
177 files = ftpClient.listFiles(); |
|
178 |
|
179 assertNotNull(files); |
|
180 |
|
181 //UNIX parseable contents on Z |
|
182 |
|
183 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/Z"))); |
|
184 files = ftpClient.listFiles(); |
|
185 assertNotNull(files); |
|
186 |
|
187 } |
|
188 |
|
189 public void testListLocation() throws IOException{ |
|
190 |
|
191 |
|
192 FTPFile[] files1; |
|
193 FTPFile[] files2; |
|
194 |
|
195 //UNIX parseable contents on /C/System |
|
196 |
|
197 files1 = ftpClient.listFiles("/C/System"); |
|
198 |
|
199 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/System"))); |
|
200 files2 = ftpClient.listFiles(); |
|
201 |
|
202 assertEquals(files2.length, files1.length); |
|
203 |
|
204 |
|
205 |
|
206 //UNIX parseable contents on root |
|
207 |
|
208 files1 = ftpClient.listFiles("/"); |
|
209 |
|
210 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
211 files2 = ftpClient.listFiles(); |
|
212 |
|
213 assertEquals(files2.length, files1.length); |
|
214 |
|
215 //UNIX parseable contents on /C |
|
216 |
|
217 files1 = ftpClient.listFiles("/C"); |
|
218 |
|
219 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
220 files2 = ftpClient.listFiles(); |
|
221 |
|
222 assertEquals(files2.length, files1.length); |
|
223 |
|
224 |
|
225 } |
|
226 |
|
227 |
|
228 public void testCreateDeleteFolder() throws IOException |
|
229 { |
|
230 //clean up |
|
231 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
232 ftpClient.removeDirectory("testFolder"); |
|
233 |
|
234 |
|
235 assertTrue(ftpClient.makeDirectory("testFolder")); |
|
236 ftpClient.removeDirectory("testFolder"); |
|
237 |
|
238 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
239 assertTrue(ftpClient.makeDirectory("/C/testFolder")); |
|
240 assertTrue(ftpClient.removeDirectory("/C/testFolder")); |
|
241 |
|
242 |
|
243 //clean up |
|
244 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
245 ftpClient.removeDirectory("testFolder"); |
|
246 |
|
247 |
|
248 } |
|
249 |
|
250 |
|
251 public void testStoreBinaryFile() throws IOException |
|
252 { |
|
253 |
|
254 //for (int i = 0; i < 20; i++) { |
|
255 assertTrue(ftpClient.storeFile("/C/testDriver_TEF_0x10210D31.sis", new FileInputStream("d:\\testDriver_TEF_0x10210D32.sis"))); |
|
256 ftpClient.deleteFile("/C/testDriver_TEF_0x10210D31.sis"); |
|
257 // System.out.println(i); |
|
258 //} |
|
259 } |
|
260 |
|
261 public void testStoreAsciiFile() throws IOException |
|
262 { |
|
263 |
|
264 //for (int i = 0; i < 20; i++) { |
|
265 // assertTrue(ftpClient.storeFile("/C/donquixote.txt", new FileInputStream("./data/donquixote.txt"))); |
|
266 ftpClient.deleteFile("/C/donquixote.txt"); |
|
267 // System.out.println(i); |
|
268 //} |
|
269 } |
|
270 |
|
271 |
|
272 public void testCreateDeleteFile() throws IOException |
|
273 { |
|
274 |
|
275 //clean possible previous failed tests |
|
276 ftpClient.deleteFile("/C/test.txt"); |
|
277 |
|
278 //from same location |
|
279 |
|
280 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
281 assertNotNull(out); |
|
282 out.write("test file".getBytes()); |
|
283 out.close(); |
|
284 ftpClient.completePendingCommand(); |
|
285 |
|
286 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
287 assertTrue(ftpClient.deleteFile("test.txt")); |
|
288 |
|
289 //from different location |
|
290 |
|
291 out = ftpClient.storeFileStream("/C/test.txt"); |
|
292 assertNotNull(out); |
|
293 out.write("test file".getBytes()); |
|
294 out.close(); |
|
295 ftpClient.completePendingCommand(); |
|
296 |
|
297 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
298 assertTrue(ftpClient.deleteFile("/C/test.txt")); |
|
299 |
|
300 } |
|
301 |
|
302 public void testRename() throws IOException { |
|
303 |
|
304 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
305 assertNotNull(out); |
|
306 out.write("test file".getBytes()); |
|
307 out.close(); |
|
308 ftpClient.completePendingCommand(); |
|
309 |
|
310 //from directory to same directory |
|
311 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
312 assertTrue(ftpClient.rename("test.txt", "test2.txt")); |
|
313 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size test2.txt"))); |
|
314 |
|
315 //from different directory |
|
316 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
317 assertTrue(ftpClient.rename("/C/test2.txt", "/C/test.txt")); |
|
318 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size test.txt"))); |
|
319 |
|
320 assertTrue(ftpClient.deleteFile("/C/test.txt")); |
|
321 |
|
322 } |
|
323 |
|
324 public void testMove() throws IOException { |
|
325 |
|
326 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
327 assertNotNull(out); |
|
328 out.write("test file".getBytes()); |
|
329 out.close(); |
|
330 ftpClient.completePendingCommand(); |
|
331 |
|
332 assertTrue(ftpClient.makeDirectory("/C/testFolder")); |
|
333 |
|
334 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
335 assertTrue(ftpClient.rename("/C/test.txt", "/C/testFolder/test.txt")); |
|
336 |
|
337 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/testFolder"))); |
|
338 assertTrue(ftpClient.rename("test.txt", "/C/test.txt")); |
|
339 assertTrue(ftpClient.rename("/C/test.txt", "test.txt")); |
|
340 |
|
341 assertTrue(ftpClient.deleteFile("/C/testFolder/test.txt")); |
|
342 assertTrue(ftpClient.removeDirectory("/C/testFolder")); |
|
343 |
|
344 } |
|
345 |
|
346 public void testCdup() throws IOException { |
|
347 |
|
348 |
|
349 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/system"))); |
|
350 |
|
351 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cdup())); |
|
352 assertEquals("/C", ftpClient.printWorkingDirectory()); |
|
353 |
|
354 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cdup())); |
|
355 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
356 |
|
357 } |
|
358 |
|
359 public void testBrowse() throws IOException { |
|
360 |
|
361 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
362 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
363 |
|
364 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("C"))); |
|
365 assertEquals("/C", ftpClient.printWorkingDirectory()); |
|
366 |
|
367 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("system"))); |
|
368 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
369 |
|
370 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
371 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
372 |
|
373 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/system"))); |
|
374 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
375 |
|
376 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
377 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
378 |
|
379 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/system/.././system"))); |
|
380 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
381 |
|
382 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd(".."))); |
|
383 assertEquals("/C", ftpClient.printWorkingDirectory()); |
|
384 |
|
385 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd(".."))); |
|
386 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
387 |
|
388 |
|
389 |
|
390 } |
|
391 |
|
392 public void testHelp() throws IOException { |
|
393 |
|
394 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("help"))); |
|
395 |
|
396 } |
|
397 |
|
398 public void testStat() throws IOException { |
|
399 |
|
400 assertTrue(FTPReply.isPositiveCompletion(ftpClient.stat())); |
|
401 |
|
402 } |
|
403 |
|
404 public void testWrongCommands() throws IOException { |
|
405 |
|
406 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("!\"?%^&*())__+"))); |
|
407 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("asdasdasdasdsdjkklahsdjkajkhsdkhajksdasjkdjkasjkdhasjkdhasdhjkashdjkhasjkdhasjdhjkashdjkhasjkdhjkashashdhasjdhjashdjhasjkhdjkashdhjkashdjkashdhasdkhasdjkahskdajkshdjkashdjkashdjkashdjkashjkdhasjkdhkashkdhasdjkahsjkdhasjkhdjkashdjkhaskdjhajkshdjkahsdjkahsdkjahksdh"))); |
|
408 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("asda sda sda sd sdj kk l \t ahs \n \r"))); |
|
409 |
|
410 } |
|
411 |
|
412 public void testGetSystemDrive() throws IOException{ |
|
413 |
|
414 assertTrue(FTPReply.isPositiveCompletion(ftpClient.stat())); |
|
415 String s = ftpClient.getReplyString(); |
|
416 assertNotNull(s); |
|
417 |
|
418 Pattern p = Pattern.compile(".*System Drive: (\\w).*", Pattern.DOTALL); //Pattern.DOTALL => '.' includes end of line |
|
419 Matcher m = p.matcher(s); |
|
420 assertTrue(m.matches()); |
|
421 |
|
422 } |
|
423 |
|
424 public void testSize() throws IOException { |
|
425 |
|
426 //try{ |
|
427 String testString = "test file"; |
|
428 |
|
429 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
430 assertNotNull(out); |
|
431 out.write(testString.getBytes()); |
|
432 out.close(); |
|
433 ftpClient.completePendingCommand(); |
|
434 |
|
435 //absolute |
|
436 //file |
|
437 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/test.txt"))); |
|
438 assertEquals(testString.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
439 |
|
440 //folder |
|
441 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("size /C/system"))); |
|
442 assertTrue(ftpClient.getReplyString().matches(".*not a plain file.*\r\n")); |
|
443 |
|
444 |
|
445 //relative |
|
446 //file |
|
447 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
448 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size test.txt"))); |
|
449 assertEquals(testString.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
450 |
|
451 //folder |
|
452 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("size system"))); |
|
453 assertTrue(ftpClient.getReplyString().matches(".*not a plain file.*\r\n")); |
|
454 |
|
455 ftpClient.deleteFile("/C/test.txt"); |
|
456 } |
|
457 |
|
458 |
|
459 //FTP&Telnet-File Transfer-001 |
|
460 //To Transfer a file of size 0 from Pc to device (H2 /H4) from current working directory |
|
461 |
|
462 public void testFTP_Telnet_File_Transfer_001() throws IOException { |
|
463 |
|
464 String fileUnderTest = "emptyFile"; |
|
465 |
|
466 File f = new File("./data/"+fileUnderTest); |
|
467 |
|
468 if(!f.exists()) |
|
469 { |
|
470 f.createNewFile(); |
|
471 } |
|
472 |
|
473 //ASCII |
|
474 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
475 |
|
476 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
477 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
478 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
479 ftpClient.deleteFile("/C/"+fileUnderTest); |
|
480 |
|
481 //BINARY |
|
482 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
483 |
|
484 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
485 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
486 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
487 ftpClient.deleteFile("/C/"+fileUnderTest); |
|
488 |
|
489 } |
|
490 |
|
491 //FTP&Telnet-File Transfer-002 |
|
492 //To Transfer a file of normal size from Pc to device (H2 /H4) from current working directory |
|
493 |
|
494 public void testFTP_Telnet_File_Transfer_002_ASCII() throws IOException { |
|
495 |
|
496 String fileUnderTest = "smallfile.txt"; |
|
497 File f = new File("./data/"+fileUnderTest); |
|
498 |
|
499 //ASCII |
|
500 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
501 |
|
502 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
503 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
504 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
505 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
506 |
|
507 //BINARY |
|
508 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
509 |
|
510 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
511 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
512 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
513 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
514 |
|
515 } |
|
516 |
|
517 //FTP&Telnet-File Transfer-002 |
|
518 //To Transfer a file of normal size from Pc to device (H2 /H4) from current working directory |
|
519 |
|
520 public void testFTP_Telnet_File_Transfer_002_BINARY() throws IOException { |
|
521 |
|
522 String fileUnderTest = "smallfile.bin"; |
|
523 File f = new File("./data/"+fileUnderTest); |
|
524 |
|
525 //ASCII |
|
526 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
527 |
|
528 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
529 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
530 assertTrue(f.length() != Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
531 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
532 |
|
533 //BINARY |
|
534 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
535 |
|
536 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
537 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
538 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
539 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
540 |
|
541 } |
|
542 |
|
543 |
|
544 //FTP&Telnet-File Transfer-003 |
|
545 //To Transfer a file of Large size from Pc to device (H2 /H4) from current working directory |
|
546 |
|
547 public void testFTP_Telnet_File_Transfer_003_ASCII() throws IOException { |
|
548 |
|
549 String fileUnderTest = "bigfile.txt"; |
|
550 File f = new File("./data/"+fileUnderTest); |
|
551 |
|
552 //ASCII |
|
553 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
554 |
|
555 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
556 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
557 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
558 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
559 |
|
560 //BINARY |
|
561 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
562 |
|
563 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
564 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
565 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
566 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
567 |
|
568 } |
|
569 |
|
570 public void testFTP_Telnet_File_Transfer_003_BINARY() throws IOException { |
|
571 |
|
572 String fileUnderTest = "bigfile.bin"; |
|
573 File f = new File("./data/"+fileUnderTest); |
|
574 |
|
575 //ASCII |
|
576 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
577 |
|
578 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
579 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
580 assertTrue(f.length() != Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
581 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
582 |
|
583 //BINARY |
|
584 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
585 |
|
586 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
587 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
588 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
589 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
590 |
|
591 } |
|
592 |
|
593 //FTP&Telnet-Connection-003 |
|
594 //To change the mode of transfer from remote host to Device (H2/H4) |
|
595 public void testFTP_Telnet_Connection_Execution_003() throws IOException |
|
596 { |
|
597 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
598 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
599 } |
|
600 |
|
601 //FTP&Telnet-File Transfer-007 |
|
602 //To Transfer a file from Pc to device (H2 /H4) from working directory to non Existence directory |
|
603 public void testFTP_Telnet_File_Transfer_007_ASCII_Mode() throws IOException |
|
604 { |
|
605 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
606 assertFalse(ftpClient.storeFile("/C/nonexistingfolder/smallfile.txt", new FileInputStream("./data/smallfile.txt"))); |
|
607 } |
|
608 |
|
609 //FTP&Telnet-File Transfer-007 |
|
610 //To Transfer a file from Pc to device (H2 /H4) from working directory to non Existence directory |
|
611 public void testFTP_Telnet_File_Transfer_007_BINARY_Mode() throws IOException |
|
612 { |
|
613 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
614 assertFalse(ftpClient.storeFile("/C/nonexistingfolder/smallfile.txt", new FileInputStream("./data/smallfile.txt"))); |
|
615 } |
|
616 |
|
617 //FTP&Telnet-File Retrieve-001 |
|
618 //To Retrieve a file of size 0 from device to PC |
|
619 |
|
620 public void testFTP_Telnet_File_Retrieve_001() throws IOException { |
|
621 |
|
622 String fileUnderTest = "emptyFile"; |
|
623 |
|
624 File f = new File("./data/"+fileUnderTest); |
|
625 |
|
626 if(!f.exists()) |
|
627 f.createNewFile(); |
|
628 |
|
629 f.deleteOnExit(); |
|
630 |
|
631 //upload and verify correctly uploaded |
|
632 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
633 |
|
634 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
635 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
636 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
637 |
|
638 |
|
639 //download file |
|
640 |
|
641 File f2 = File.createTempFile("FTP_Telnet_File_Retrieve_001",".txt"); |
|
642 File f3 = File.createTempFile("FTP_Telnet_File_Retrieve_001",".bin"); |
|
643 f2.deleteOnExit(); |
|
644 f3.deleteOnExit(); |
|
645 |
|
646 //ASCII download |
|
647 |
|
648 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
649 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f2))); |
|
650 assertEquals(f.length(), f2.length()); |
|
651 |
|
652 //BINARY download |
|
653 |
|
654 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
655 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f3))); |
|
656 assertEquals(f.length(), f3.length()); |
|
657 |
|
658 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
659 |
|
660 } |
|
661 |
|
662 //FTP&Telnet-File Retrieve-002 |
|
663 //To Retrieve a file of normal size from device to Pc |
|
664 |
|
665 public void testFTP_Telnet_File_Retrieve_002_ASCII() throws IOException { |
|
666 |
|
667 String fileUnderTest = "smallfile.txt"; |
|
668 File f = new File("./data/"+fileUnderTest); |
|
669 |
|
670 //ASCII |
|
671 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
672 |
|
673 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
674 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
675 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
676 |
|
677 //download file |
|
678 |
|
679 File f2 = File.createTempFile("FTP_Telnet_File_Retrieve_002_ASCII",".txt"); |
|
680 File f3 = File.createTempFile("FTP_Telnet_File_Retrieve_002_ASCII",".bin"); |
|
681 f3.deleteOnExit(); |
|
682 f2.deleteOnExit(); |
|
683 |
|
684 //ASCII download |
|
685 |
|
686 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
687 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f2))); |
|
688 assertEquals(f.length(), f2.length()); |
|
689 |
|
690 //BINARY download |
|
691 |
|
692 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
693 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f3))); |
|
694 assertEquals(f.length(), f3.length()); |
|
695 |
|
696 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
697 |
|
698 } |
|
699 |
|
700 //FTP&Telnet-File Retrieve-002 |
|
701 //To Transfer a file of normal size from device to pc |
|
702 |
|
703 public void testFTP_Telnet_File_Retrieve_002_BINARY() throws IOException { |
|
704 |
|
705 String fileUnderTest = "smallfile.bin"; |
|
706 File f = new File("./data/"+fileUnderTest); |
|
707 |
|
708 //BINARY |
|
709 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
710 |
|
711 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
712 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
713 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
714 |
|
715 //download file |
|
716 |
|
717 File f2 = File.createTempFile("FTP_Telnet_File_Retrieve_002_BINARY",".txt"); |
|
718 File f3 = File.createTempFile("FTP_Telnet_File_Retrieve_002_BINARY",".bin"); |
|
719 f2.deleteOnExit(); |
|
720 f3.deleteOnExit(); |
|
721 |
|
722 //ASCII download |
|
723 |
|
724 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
725 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f2))); |
|
726 assertEquals(f.length() , f2.length()); |
|
727 |
|
728 //BINARY download |
|
729 |
|
730 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
731 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f3))); |
|
732 assertEquals(f.length(), f3.length()); |
|
733 |
|
734 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
735 |
|
736 |
|
737 |
|
738 } |
|
739 |
|
740 |
|
741 //FTP&Telnet-File Retrieve-003 |
|
742 //To Transfer a file of Large size from device to pc |
|
743 |
|
744 public void testFTP_Telnet_File_Retrieve_003_ASCII() throws IOException { |
|
745 |
|
746 String fileUnderTest = "bigfile.txt"; |
|
747 File f = new File("./data/"+fileUnderTest); |
|
748 |
|
749 //ASCII |
|
750 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
751 |
|
752 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
753 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
754 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
755 |
|
756 //download file |
|
757 |
|
758 File f2 = File.createTempFile("testFTP_Telnet_File_Retrieve_003_ASCII",".txt"); |
|
759 File f3 = File.createTempFile("testFTP_Telnet_File_Retrieve_003_ASCII",".bin"); |
|
760 f2.deleteOnExit(); |
|
761 |
|
762 //ASCII download |
|
763 |
|
764 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
765 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f2))); |
|
766 assertEquals(f.length(), f2.length()); |
|
767 |
|
768 //BINARY download |
|
769 |
|
770 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
771 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f3))); |
|
772 assertEquals(f.length(), f3.length()); |
|
773 |
|
774 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
775 |
|
776 } |
|
777 |
|
778 //FTP&Telnet-File Retrieve-003 |
|
779 //To Transfer a file of Large size from device to pc |
|
780 |
|
781 |
|
782 public void testFTP_Telnet_File_Retrieve_003_BINARY() throws IOException { |
|
783 |
|
784 String fileUnderTest = "bigfile.bin"; |
|
785 File f = new File("./data/"+fileUnderTest); |
|
786 |
|
787 //BINARY |
|
788 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
789 |
|
790 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
791 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
792 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
793 |
|
794 //download file |
|
795 |
|
796 File f2 = File.createTempFile("FTP_Telnet_File_Retrieve_003_BINARY",".txt"); |
|
797 File f3 = File.createTempFile("FTP_Telnet_File_Retrieve_003_BINARY",".bin"); |
|
798 f2.deleteOnExit(); |
|
799 f3.deleteOnExit(); |
|
800 |
|
801 //ASCII download |
|
802 |
|
803 assertTrue(ftpClient.setFileType(FTP.ASCII_FILE_TYPE)); |
|
804 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f2))); |
|
805 assertEquals(f.length() , f2.length()); |
|
806 |
|
807 //BINARY download |
|
808 |
|
809 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
810 assertTrue(ftpClient.retrieveFile("/C/"+fileUnderTest, new FileOutputStream(f3))); |
|
811 assertEquals(f.length(), f3.length()); |
|
812 |
|
813 |
|
814 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
815 |
|
816 } |
|
817 |
|
818 //FTP&Telnet-File Retrieve-009 |
|
819 //retrieve from non-existing directory |
|
820 |
|
821 public void testFTP_Telnet_File_Retrieve_009() throws IOException { |
|
822 |
|
823 assertFalse(ftpClient.retrieveFile("/C/nonexisting", System.out)); |
|
824 |
|
825 } |
|
826 |
|
827 //FTP&Telnet-File Retrieve-016 |
|
828 //To Retrieve a Directory from device (H2 /H4) to PC |
|
829 |
|
830 public void testFTP_Telnet_File_Retrieve_016() throws IOException { |
|
831 |
|
832 assertFalse(ftpClient.retrieveFile("/C/system", System.out)); |
|
833 |
|
834 } |
|
835 |
|
836 //FTP&Telnet-File Delete-001 |
|
837 //To Delete a file of size 0 from Pc |
|
838 |
|
839 public void testFTP_Telnet_File_Delete_001() throws IOException { |
|
840 |
|
841 String fileUnderTest = "emptyFile"; |
|
842 |
|
843 File f = new File("./data/"+fileUnderTest); |
|
844 |
|
845 //upload and verify correctly uploaded |
|
846 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
847 |
|
848 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
849 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
850 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
851 |
|
852 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
853 |
|
854 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
855 } |
|
856 |
|
857 //FTP&Telnet-File Delete-003 |
|
858 //To Delete a file of normal size on Device (H2/H4) from Pc |
|
859 public void testFTP_Telnet_File_Delete_003() throws IOException { |
|
860 |
|
861 String fileUnderTest = "smallfile.bin"; |
|
862 File f = new File("./data/"+fileUnderTest); |
|
863 |
|
864 //BINARY |
|
865 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
866 |
|
867 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
868 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
869 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
870 |
|
871 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
872 |
|
873 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
874 } |
|
875 |
|
876 //FTP&Telnet-File Delete-004 |
|
877 //To Delete a file of Large size on Device (H2/H4) from Pc |
|
878 public void testFTP_Telnet_File_Delete_004() throws IOException { |
|
879 |
|
880 String fileUnderTest = "bigfile.bin"; |
|
881 File f = new File("./data/"+fileUnderTest); |
|
882 |
|
883 //BINARY |
|
884 assertTrue(ftpClient.setFileType(FTP.BINARY_FILE_TYPE)); |
|
885 |
|
886 assertTrue(ftpClient.storeFile("/C/"+fileUnderTest, new FileInputStream(f))); |
|
887 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
888 assertEquals(f.length(), Integer.parseInt(ftpClient.getReplyString().substring(4).trim())); |
|
889 |
|
890 assertTrue(ftpClient.deleteFile("/C/"+fileUnderTest)); |
|
891 |
|
892 assertTrue(FTPReply.isNegativePermanent(ftpClient.sendCommand("size /C/"+fileUnderTest))); |
|
893 } |
|
894 |
|
895 //FTP&Telnet-File Delete-006 |
|
896 //To Delete a non existent file on Device (H2/H4) from Pc |
|
897 public void testFTP_Telnet_File_Delete_006() throws IOException { |
|
898 |
|
899 assertFalse(ftpClient.deleteFile("/C/nonexistingfile")); |
|
900 } |
|
901 |
|
902 //FTP&Telnet-File Retrieve-018 |
|
903 //To Retrieve a drive listing on Device (H2/H4) from Pc |
|
904 public void testFTP_Telnet_File_Retrieve_018() throws IOException { |
|
905 |
|
906 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
907 FTPFile[] drives = ftpClient.listFiles(); |
|
908 |
|
909 assertNotNull(drives); |
|
910 |
|
911 for (int i = 0; i < drives.length; i++) { |
|
912 |
|
913 String driveName = drives[i].getName(); |
|
914 |
|
915 assertTrue(driveName.length() == 1 && driveName.charAt(0) >= 'A' |
|
916 && driveName.charAt(0) <= 'Z'); |
|
917 } |
|
918 |
|
919 } |
|
920 |
|
921 |
|
922 // FTP&Telnet-File Retrieve-019 |
|
923 //To Retrieve a directory listing on Device (H2/H4) from Pc |
|
924 |
|
925 public void testFTP_Telnet_File_Retrieve_019() throws IOException{ |
|
926 |
|
927 FTPFile[] files; |
|
928 |
|
929 //UNIX parseable contents on C |
|
930 |
|
931 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
932 files = ftpClient.listFiles(); |
|
933 |
|
934 assertNotNull(files); |
|
935 |
|
936 //UNIX parseable contents on Z |
|
937 |
|
938 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/Z"))); |
|
939 files = ftpClient.listFiles(); |
|
940 assertNotNull(files); |
|
941 |
|
942 } |
|
943 |
|
944 //FTP&Telnet-File Retrieve-020 |
|
945 //To check a particular file/Folder on Device (H2/H4) from Pc |
|
946 |
|
947 public void testFTP_Telnet_File_Retrieve_020() throws IOException{ |
|
948 |
|
949 FTPFile[] files; |
|
950 String[] names; |
|
951 |
|
952 boolean found = false; |
|
953 |
|
954 //folder |
|
955 //List C:\System |
|
956 |
|
957 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
958 files = ftpClient.listFiles(); |
|
959 |
|
960 for (int i = 0; i < files.length; i++) { |
|
961 if(files[i].getName().equalsIgnoreCase("System") && files[i].isDirectory()) |
|
962 found = true; |
|
963 } |
|
964 |
|
965 assertTrue(found); |
|
966 |
|
967 found = false; |
|
968 |
|
969 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
970 |
|
971 names = ftpClient.listNames(); |
|
972 |
|
973 for (int i = 0; i < names.length; i++) { |
|
974 if(names[i].equalsIgnoreCase("System")) |
|
975 found = true; |
|
976 } |
|
977 |
|
978 assertTrue(found); |
|
979 |
|
980 found = false; |
|
981 |
|
982 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
983 |
|
984 files = ftpClient.listFiles("/C"); |
|
985 |
|
986 for (int i = 0; i < files.length; i++) { |
|
987 if(files[i].getName().equalsIgnoreCase("System") && files[i].isDirectory()) |
|
988 found = true; |
|
989 } |
|
990 |
|
991 assertTrue(found); |
|
992 |
|
993 |
|
994 found = false; |
|
995 |
|
996 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
997 |
|
998 names = ftpClient.listNames("/C"); |
|
999 |
|
1000 for (int i = 0; i < names.length; i++) { |
|
1001 if(names[i].equalsIgnoreCase("System")) |
|
1002 found = true; |
|
1003 } |
|
1004 |
|
1005 assertTrue(found); |
|
1006 |
|
1007 |
|
1008 found = false; |
|
1009 |
|
1010 //file |
|
1011 //List C:\System\System.ini |
|
1012 |
|
1013 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/System"))); |
|
1014 files = ftpClient.listFiles(); |
|
1015 |
|
1016 for (int i = 0; i < files.length; i++) { |
|
1017 if(files[i].getName().equalsIgnoreCase("System.ini") && files[i].isFile()) |
|
1018 found = true; |
|
1019 } |
|
1020 |
|
1021 assertTrue(found); |
|
1022 |
|
1023 found = false; |
|
1024 |
|
1025 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/System"))); |
|
1026 |
|
1027 names = ftpClient.listNames(); |
|
1028 |
|
1029 for (int i = 0; i < names.length; i++) { |
|
1030 if(names[i].equalsIgnoreCase("System.ini")) |
|
1031 found = true; |
|
1032 } |
|
1033 |
|
1034 assertTrue(found); |
|
1035 |
|
1036 found = false; |
|
1037 |
|
1038 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1039 files = ftpClient.listFiles("/C/System"); |
|
1040 |
|
1041 for (int i = 0; i < files.length; i++) { |
|
1042 if(files[i].getName().equalsIgnoreCase("System.ini") && files[i].isFile()) |
|
1043 found = true; |
|
1044 } |
|
1045 |
|
1046 assertTrue(found); |
|
1047 |
|
1048 |
|
1049 found = false; |
|
1050 |
|
1051 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1052 |
|
1053 names = ftpClient.listNames("/C/System"); |
|
1054 |
|
1055 for (int i = 0; i < names.length; i++) { |
|
1056 if(names[i].equalsIgnoreCase("System.ini")) |
|
1057 found = true; |
|
1058 } |
|
1059 |
|
1060 assertTrue(found); |
|
1061 |
|
1062 |
|
1063 } |
|
1064 |
|
1065 //FTP&Telnet-Directory-001 + 002 |
|
1066 //To create a Directory on device(H2/H4) from PC Side |
|
1067 //To Remove a Directory on device(H2/H4) from PC Side |
|
1068 |
|
1069 public void testFTP_Telnet_Directory_001() throws IOException{ |
|
1070 |
|
1071 boolean found = false; |
|
1072 |
|
1073 //create folder |
|
1074 assertTrue(ftpClient.makeDirectory("/C/newFolder")); |
|
1075 |
|
1076 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
1077 FTPFile[] files = ftpClient.listFiles(); |
|
1078 |
|
1079 for (int i = 0; i < files.length; i++) { |
|
1080 if(files[i].getName().equalsIgnoreCase("newFolder") && files[i].isDirectory()) |
|
1081 found = true; |
|
1082 } |
|
1083 |
|
1084 assertTrue(found); |
|
1085 |
|
1086 found = false; |
|
1087 |
|
1088 //delete folder |
|
1089 assertTrue(ftpClient.removeDirectory("/C/newFolder")); |
|
1090 |
|
1091 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
1092 files = ftpClient.listFiles(); |
|
1093 |
|
1094 for (int i = 0; i < files.length; i++) { |
|
1095 if(files[i].getName().equalsIgnoreCase("newFolder") && files[i].isDirectory()) |
|
1096 found = true; |
|
1097 } |
|
1098 |
|
1099 assertFalse(found); |
|
1100 |
|
1101 } |
|
1102 |
|
1103 //FTP&Telnet-Directory-003 |
|
1104 //To Rename a file on device(H2/H4) from PC Side |
|
1105 |
|
1106 public void testFTP_Telnet_Directory_003() throws IOException{ |
|
1107 |
|
1108 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
1109 assertNotNull(out); |
|
1110 out.write("test file".getBytes()); |
|
1111 out.close(); |
|
1112 ftpClient.completePendingCommand(); |
|
1113 |
|
1114 //from directory to same directory |
|
1115 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C"))); |
|
1116 assertTrue(ftpClient.rename("test.txt", "test2.txt")); |
|
1117 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size test2.txt"))); |
|
1118 |
|
1119 //from different directory |
|
1120 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1121 assertTrue(ftpClient.rename("/C/test2.txt", "/C/test.txt")); |
|
1122 assertTrue(FTPReply.isPositiveCompletion(ftpClient.sendCommand("size test.txt"))); |
|
1123 |
|
1124 assertTrue(ftpClient.deleteFile("/C/test.txt")); |
|
1125 } |
|
1126 |
|
1127 //FTP&Telnet-Directory-004 |
|
1128 //To Move a file on device(H2/H4) from PC Side |
|
1129 |
|
1130 public void testFTP_Telnet_Directory_004() throws IOException{ |
|
1131 OutputStream out = ftpClient.storeFileStream("/C/test.txt"); |
|
1132 assertNotNull(out); |
|
1133 out.write("test file".getBytes()); |
|
1134 out.close(); |
|
1135 ftpClient.completePendingCommand(); |
|
1136 |
|
1137 assertTrue(ftpClient.makeDirectory("/C/testFolder")); |
|
1138 |
|
1139 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1140 assertTrue(ftpClient.rename("/C/test.txt", "/C/testFolder/test.txt")); |
|
1141 |
|
1142 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/testFolder"))); |
|
1143 assertTrue(ftpClient.rename("test.txt", "/C/test.txt")); |
|
1144 assertTrue(ftpClient.rename("/C/test.txt", "test.txt")); |
|
1145 |
|
1146 assertTrue(ftpClient.deleteFile("/C/testFolder/test.txt")); |
|
1147 assertTrue(ftpClient.removeDirectory("/C/testFolder")); |
|
1148 } |
|
1149 |
|
1150 //FTP&Telnet-Directory-006 |
|
1151 //To Change the current directory on device(H2/H4) from PC Side |
|
1152 public void testFTP_Telnet_Directory_006() throws IOException{ |
|
1153 |
|
1154 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1155 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
1156 |
|
1157 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("C"))); |
|
1158 assertEquals("/C", ftpClient.printWorkingDirectory()); |
|
1159 |
|
1160 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("system"))); |
|
1161 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
1162 |
|
1163 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1164 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
1165 |
|
1166 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/system"))); |
|
1167 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
1168 |
|
1169 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/"))); |
|
1170 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
1171 |
|
1172 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd("/C/system/.././system"))); |
|
1173 assertEquals("/C/system", ftpClient.printWorkingDirectory()); |
|
1174 |
|
1175 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd(".."))); |
|
1176 assertEquals("/C", ftpClient.printWorkingDirectory()); |
|
1177 |
|
1178 assertTrue(FTPReply.isPositiveCompletion(ftpClient.cwd(".."))); |
|
1179 assertEquals("/", ftpClient.printWorkingDirectory()); |
|
1180 |
|
1181 } |
|
1182 |
|
1183 //FTP&Telnet-Directory-007 |
|
1184 //To change a current working directory from a valid directory to a non existence directory from PC to Device(H2/H4) |
|
1185 public void testFTP_Telnet_Directory_007() throws IOException{ |
|
1186 assertTrue(FTPReply.isNegativePermanent(ftpClient.cwd("/ajdaskldjklasdjlasjdlasldjklasjdl"))); |
|
1187 assertTrue(FTPReply.isNegativePermanent(ftpClient.cwd("/C/ajdaskldjklasdjlasjdlasldjklasjdl"))); |
|
1188 } |
|
1189 |
|
1190 //FTP&Telnet-Directory-008 |
|
1191 //To change a current working directory from a valid directory to a non existence directory of different drive from PC to Device(H2/H4) |
|
1192 |
|
1193 |
|
1194 } |