1/* 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.CommandHandler 19import org.mockftpserver.core.server.AbstractFtpServer 20import org.mockftpserver.core.server.AbstractFtpServerTest 21import org.mockftpserver.fake.FakeFtpServer 22import org.mockftpserver.fake.TestCommandHandler 23import org.mockftpserver.fake.TestCommandHandlerNotServerConfigurationAware 24import org.mockftpserver.fake.UserAccount 25 26 27/** 28 * Tests for FakeFtpServer. 29 * 30 * @version $Revision: 54 $ - $Date: 2008-05-13 21:54:53 -0400 (Tue, 13 May 2008) $ 31 * 32 * @author Chris Mair 33 */ 34class FakeFtpServerTest extends AbstractFtpServerTest { 35 36 def commandHandler 37 def commandHandler_NotServerConfigurationAware 38 39 //------------------------------------------------------------------------- 40 // Extra tests (Standard tests defined in superclass) 41 //------------------------------------------------------------------------- 42 43 /** 44 * Test the setCommandHandler() method, for a CommandHandler that does not implement ResourceBundleAware 45 */ 46 void testSetCommandHandler_NotServerConfigurationAware() { 47 ftpServer.setCommandHandler("ZZZ", commandHandler_NotServerConfigurationAware); 48 assert ftpServer.getCommandHandler("ZZZ") == commandHandler_NotServerConfigurationAware 49 } 50 51 /** 52 * Test the setCommandHandler() method, for a CommandHandler that implements ReplyTextBundleAware, 53 * and whose replyTextBundle attribute is null. 54 */ 55 void testSetCommandHandler_ServerConfigurationAware() { 56 ftpServer.setCommandHandler("ZZZ", commandHandler); 57 assert ftpServer.getCommandHandler("ZZZ") == commandHandler 58 assert ftpServer == commandHandler.serverConfiguration 59 } 60 61 void testUserAccounts() { 62 def userAccount = new UserAccount(username: 'abc') 63 64 // addUserAccount() 65 ftpServer.addUserAccount(userAccount) 66 assert ftpServer.getUserAccount("abc") == userAccount 67 68 // setUserAccounts 69 def userAccounts = [userAccount] 70 ftpServer.userAccounts = userAccounts 71 assert ftpServer.getUserAccount("abc") == userAccount 72 } 73 74 void testHelpText() { 75 ftpServer.helpText = [a: 'aaaaa', b: 'bbbbb', '': 'default'] 76 assert ftpServer.getHelpText('a') == 'aaaaa' 77 assert ftpServer.getHelpText('b') == 'bbbbb' 78 assert ftpServer.getHelpText('') == 'default' 79 assert ftpServer.getHelpText('unrecognized') == null 80 } 81 82 void testSystemName() { 83 assert ftpServer.systemName == "WINDOWS" 84 ftpServer.systemName = "abc" 85 assert ftpServer.systemName == "abc" 86 } 87 88 void testReplyText() { 89 ftpServer.replyTextBaseName = "SampleReplyText" 90 91 ResourceBundle resourceBundle = ftpServer.replyTextBundle 92 assert resourceBundle.getString("110") == "Testing123" 93 } 94 95 //------------------------------------------------------------------------- 96 // Test set up 97 //------------------------------------------------------------------------- 98 99 void setUp() { 100 super.setUp(); 101 commandHandler = new TestCommandHandler() 102 commandHandler_NotServerConfigurationAware = new TestCommandHandlerNotServerConfigurationAware() 103 } 104 105 //------------------------------------------------------------------------- 106 // Abstract method implementations 107 //------------------------------------------------------------------------- 108 109 protected AbstractFtpServer createFtpServer() { 110 return new FakeFtpServer(); 111 } 112 113 protected CommandHandler createCommandHandler() { 114 return new TestCommandHandler(); 115 } 116 117 protected void verifyCommandHandlerInitialized(CommandHandler commandHandler) { 118 //To change body of implemented methods use File | Settings | File Templates. 119 } 120 121} 122