blob: e7e2597a2bffa18c70e1c750d556ea3ee84c3bd3 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.fake
17
18import org.mockftpserver.core.command.Command
19import org.mockftpserver.core.command.CommandHandler
20import org.mockftpserver.core.command.ReplyTextBundleAware
21import org.mockftpserver.core.server.AbstractFtpServer
22import org.mockftpserver.core.server.AbstractFtpServerTestCase
23import org.mockftpserver.core.session.Session
24
25/**
26 * Tests for FakeFtpServer.
27 *
28 * @version $Revision$ - $Date$
29 *
30 * @author Chris Mair
31 */
32class FakeFtpServerTest extends AbstractFtpServerTestCase {
33
34 def commandHandler
35 def commandHandler_NotServerConfigurationAware
36
37 //-------------------------------------------------------------------------
38 // Extra tests (Standard tests defined in superclass)
39 //-------------------------------------------------------------------------
40
41 void testSetCommandHandler_NotServerConfigurationAware() {
42 ftpServer.setCommandHandler("ZZZ", commandHandler_NotServerConfigurationAware)
43 assert ftpServer.getCommandHandler("ZZZ") == commandHandler_NotServerConfigurationAware
44 }
45
46 void testSetCommandHandler_ServerConfigurationAware() {
47 ftpServer.setCommandHandler("ZZZ", commandHandler)
48 assert ftpServer.getCommandHandler("ZZZ") == commandHandler
49 assert ftpServer == commandHandler.serverConfiguration
50 }
51
52 void testSetCommandHandler_ReplyTextBundleAware() {
53 def cmdHandler = new TestCommandHandlerReplyTextBundleAware()
54 ftpServer.setCommandHandler("ZZZ", cmdHandler)
55 assert ftpServer.getCommandHandler("ZZZ") == cmdHandler
56 assert ftpServer.replyTextBundle == cmdHandler.replyTextBundle
57 }
58
59 void testUserAccounts() {
60 def userAccount = new UserAccount(username: 'abc')
61
62 // addUserAccount()
63 ftpServer.addUserAccount(userAccount)
64 assert ftpServer.getUserAccount("abc") == userAccount
65
66 // setUserAccounts
67 def userAccounts = [userAccount]
68 ftpServer.userAccounts = userAccounts
69 assert ftpServer.getUserAccount("abc") == userAccount
70 }
71
72 void testHelpText() {
73 ftpServer.helpText = [a: 'aaaaa', b: 'bbbbb', '': 'default']
74 assert ftpServer.getHelpText('a') == 'aaaaa'
75 assert ftpServer.getHelpText('b') == 'bbbbb'
76 assert ftpServer.getHelpText('') == 'default'
77 assert ftpServer.getHelpText('unrecognized') == null
78 }
79
80 void testSystemName() {
81 assert ftpServer.systemName == "WINDOWS"
82 ftpServer.systemName = "abc"
83 assert ftpServer.systemName == "abc"
84 }
85
86 void testSystemStatus() {
87 assert ftpServer.systemStatus == "Connected"
88 ftpServer.systemStatus = "abc"
89 assert ftpServer.systemStatus == "abc"
90 }
91
92 void testReplyText() {
93 ftpServer.replyTextBaseName = "SampleReplyText"
94
95 ResourceBundle resourceBundle = ftpServer.replyTextBundle
96 assert resourceBundle.getString("110") == "Testing123"
97 }
98
99 //-------------------------------------------------------------------------
100 // Test set up
101 //-------------------------------------------------------------------------
102
103 void setUp() {
104 super.setUp();
105 commandHandler = new TestCommandHandler()
106 commandHandler_NotServerConfigurationAware = new TestCommandHandlerNotServerConfigurationAware()
107 }
108
109 //-------------------------------------------------------------------------
110 // Abstract method implementations
111 //-------------------------------------------------------------------------
112
113 protected AbstractFtpServer createFtpServer() {
114 return new FakeFtpServer();
115 }
116
117 protected CommandHandler createCommandHandler() {
118 return new TestCommandHandler();
119 }
120
121 protected void verifyCommandHandlerInitialized(CommandHandler commandHandler) {
122 //To change body of implemented methods use File | Settings | File Templates.
123 }
124
125}
126class TestCommandHandlerReplyTextBundleAware implements CommandHandler, ReplyTextBundleAware {
127 ResourceBundle replyTextBundle
128
129 public void handleCommand(Command command, Session session) {
130 }
131
132}