01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.unit;
07:
08: import org.h2.server.ftp.FtpEvent;
09: import org.h2.server.ftp.FtpEventListener;
10: import org.h2.server.ftp.FtpServer;
11: import org.h2.test.TestBase;
12: import org.h2.tools.Server;
13:
14: /**
15: * Tests the FTP server tool.
16: */
17: public class TestFtp extends TestBase implements FtpEventListener {
18:
19: private FtpEvent lastEvent;
20:
21: public void test() throws Exception {
22: test(baseDir);
23: }
24:
25: private void test(String dir) throws Exception {
26: Server server = Server.createFtpServer(
27: new String[] { "-ftpDir", dir, "-ftpPort", "8121" })
28: .start();
29: FtpServer ftp = (FtpServer) server.getService();
30: ftp.setEventListener(this );
31: FtpClient client = FtpClient.open("localhost:8121");
32: client.login("sa", "sa");
33: client.makeDirectory("test");
34: client.changeWorkingDirectory("test");
35: check(lastEvent.getCommand(), "CWD");
36: client.makeDirectory("hello");
37: client.changeWorkingDirectory("hello");
38: client.changeDirectoryUp();
39: check(lastEvent.getCommand(), "CDUP");
40: client.nameList("hello");
41: client.removeDirectory("hello");
42: client.close();
43: server.stop();
44: }
45:
46: public void beforeCommand(FtpEvent event) {
47: lastEvent = event;
48: }
49:
50: public void afterCommand(FtpEvent event) {
51: lastEvent = event;
52: }
53:
54: public void onUnsupportedCommand(FtpEvent event) {
55: lastEvent = event;
56: }
57:
58: }
|