summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrismair <chrismair@531de8e6-9941-0410-b38b-9a92acbe0330>2008-05-27 01:40:29 +0000
committerchrismair <chrismair@531de8e6-9941-0410-b38b-9a92acbe0330>2008-05-27 01:40:29 +0000
commitd52a41102a9f89b182a0062e429cc5c9b0cc5fc4 (patch)
tree49dc58c1d1c4b26c1863cea3ef5e8f9c74d5509b
parent47712ff43a2b7a33f58fc18afd01929a2e4c626f (diff)
downloadmockftpserver-d52a41102a9f89b182a0062e429cc5c9b0cc5fc4.tar.gz
Support for CONNECT (pseudo)command
git-svn-id: svn://svn.code.sf.net/p/mockftpserver/code@58 531de8e6-9941-0410-b38b-9a92acbe0330
-rw-r--r--MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/ConnectCommandHandler.groovy40
-rw-r--r--MockFtpServer/src/test/groovy/org/mockftpserver/fake/command/ConnectCommandHandlerTest.groovy49
2 files changed, 89 insertions, 0 deletions
diff --git a/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/ConnectCommandHandler.groovy b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/ConnectCommandHandler.groovy
new file mode 100644
index 0000000..bdeb22c
--- /dev/null
+++ b/MockFtpServer/src/main/groovy/org/mockftpserver/fake/command/ConnectCommandHandler.groovy
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.mockftpserver.fake.command
+
+import org.mockftpserver.core.command.Command
+import org.mockftpserver.core.command.ReplyCodes
+import org.mockftpserver.core.session.Session
+import org.mockftpserver.fake.command.AbstractFakeCommandHandler
+
+/**
+ * CommandHandler that encapsulates the sending of the reply for the initial connection from the
+ * FTP client to the server. Send back a reply code of 220, indicating a successful connection.
+ * <p>
+ * Note that this is a "special" CommandHandler, in that it handles the initial
+ * connection from the client, rather than an explicit FTP command.
+ *
+ * @version $Revision$ - $Date$
+ *
+ * @author Chris Mair
+ */
+class ConnectCommandHandler extends AbstractFakeCommandHandler {
+
+ protected void handle(Command command, Session session) {
+ sendReply(session, ReplyCodes.CONNECT_OK)
+ }
+
+} \ No newline at end of file
diff --git a/MockFtpServer/src/test/groovy/org/mockftpserver/fake/command/ConnectCommandHandlerTest.groovy b/MockFtpServer/src/test/groovy/org/mockftpserver/fake/command/ConnectCommandHandlerTest.groovy
new file mode 100644
index 0000000..335d0ee
--- /dev/null
+++ b/MockFtpServer/src/test/groovy/org/mockftpserver/fake/command/ConnectCommandHandlerTest.groovy
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.mockftpserver.fake.command
+
+import org.mockftpserver.core.command.Command
+import org.mockftpserver.core.command.CommandHandler
+import org.mockftpserver.core.command.CommandNames
+import org.mockftpserver.core.command.ReplyCodes
+
+/**
+ * Tests for ConnectCommandHandler
+ *
+ * @version $Revision$ - $Date$
+ *
+ * @author Chris Mair
+ */
+class ConnectCommandHandlerTest extends AbstractFakeCommandHandlerTest {
+
+ void testHandleCommand() {
+ commandHandler.handleCommand(createCommand([]), session)
+ assertSessionReply(ReplyCodes.CONNECT_OK)
+ }
+
+ //-------------------------------------------------------------------------
+ // Helper Methods
+ //-------------------------------------------------------------------------
+
+ CommandHandler createCommandHandler() {
+ new ConnectCommandHandler()
+ }
+
+ Command createValidCommand() {
+ return new Command(CommandNames.CONNECT, [])
+ }
+
+} \ No newline at end of file