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 package net.sf.hermesftp.server.impl;
26
27 import java.io.IOException;
28
29 import net.sf.hermesftp.SpringUtil;
30 import net.sf.hermesftp.client.FtpTestClient;
31 import net.sf.hermesftp.common.BeanConstants;
32 import net.sf.hermesftp.common.FtpConstants;
33 import net.sf.hermesftp.server.FtpServer;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37 import org.junit.After;
38 import org.junit.Before;
39
40
41
42 /***
43 * Abstract test case that sets up the communication infrastructure between FTP
44 * client and server.
45 *
46 * @author Lars Behnke
47 */
48 public abstract class AbstractClientServerTestCase implements FtpConstants,
49 BeanConstants {
50
51 private static final int SERVER_DELAY = 800;
52
53 private static Log log = LogFactory
54 .getLog(ServerRFC959Test.class);
55
56 private FtpTestClient client;
57
58 static {
59 log.info("Starting FTP servers...");
60 startServer((FtpServer) SpringUtil.getBean("testServer"));
61 }
62
63 private static void startServer(FtpServer svr) {
64 Thread svrThread = new Thread(svr);
65 svrThread.start();
66 while (svr.getStatus() != SERVER_STATUS_READY) {
67 try {
68 Thread.sleep(SERVER_DELAY);
69 } catch (InterruptedException e) {
70 log.error(e);
71 break;
72 }
73 }
74 }
75
76 /***
77 * {@inheritDoc}
78 */
79 @Before
80 public void setUp() {
81 try {
82 getClient().openConnection(null, "user", "user");
83 getClient().openPassiveMode();
84 } catch (IOException e) {
85 log.error(e);
86 }
87 }
88
89 /***
90 * {@inheritDoc}
91 */
92 @After
93 public void tearDown() throws Exception {
94 getClient().closeConnection();
95 }
96
97 /***
98 * Getter method for the java bean <code>client</code>.
99 *
100 * @return Returns the value of the java bean <code>client</code>.
101 * @throws IOException Error on initializing the FTP client.
102 */
103 protected FtpTestClient getClient() throws IOException {
104 if (client == null) {
105 client = new FtpTestClient();
106 }
107 return client;
108 }
109
110 }
111
112
113