1 // re/mind - Remote Reminder Software
2 // Copyright (C) 2002 Moritz Petersen
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // $Id: FTPClientTest.java,v 1.1.1.1 2002/09/29 17:26:04 powerpete Exp $
19 package de.jface.remind.io;
20
21 import de.jface.remind.Config;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.ByteArrayOutputStream;
25 import java.io.InputStream;
26 import java.io.OutputStream;
27
28 import junit.framework.TestCase;
29
30 import org.apache.commons.net.ftp.FTPClient;
31 import org.apache.commons.net.ftp.FTPReply;
32
33 /***
34 * The test case <code>FTPClientTest</code>
35 * tests the [your text here].
36 *
37 * @author Moritz Petersen
38 * @version $Revision: 1.1.1.1 $
39 */
40 public class FTPClientTest extends TestCase
41 {
42 private FTPClient ftp;
43
44 /***
45 * This constructor creates a new
46 * FTPClientTest test case.
47 */
48 public FTPClientTest(String name)
49 {
50 super(name);
51 }
52
53 protected void setUp() throws Exception
54 {
55 UserPreferences preferences = UserPreferences.getInstance();
56 String user = preferences.getUser();
57 String host = preferences.getHost();
58 String password = preferences.getPassword();
59
60 ftp = new FTPClient();
61
62
63 // connect
64 ftp.connect(host);
65
66 if (!FTPReply.isPositiveCompletion(ftp.getReplyCode()))
67 {
68 ftp.disconnect();
69 throw new StorageException("Access to FTP server failed.");
70 }
71
72 ftp.login(user, password);
73 }
74
75 protected void tearDown()
76 throws Exception
77 {
78 ftp.logout();
79 ftp.disconnect();
80 }
81
82 /***
83 * This method tests [your text here].
84 */
85 public void testFTP() throws Exception
86 {
87 // store
88 String str = "foo bar";
89
90 InputStream in = new ByteArrayInputStream(str.getBytes());
91
92 assertTrue("input stream is empty.", in.available() > 0);
93
94 String filename = "test.txt";
95
96 assertTrue("store file failed.", ftp.storeFile(filename, in));
97
98 // retrieve
99 ByteArrayOutputStream out = new ByteArrayOutputStream();
100
101 ftp.retrieveFile(filename, out);
102
103 String outString = out.toString();
104
105 assertEquals("file contains wrong text.", str, outString);
106 }
107 }
108
109 // ------1---------2---------3---------4---------5---------6---------7---------8
This page was automatically generated by Maven