RnfrCommandHandlerTest.groovy revision 7d4a3a2990f1a386eaf9d50cf05a9d45fab32de6
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.command 17 18import org.mockftpserver.test.AbstractGroovyTest 19import org.mockftpserver.core.command.Command 20import org.mockftpserver.core.command.CommandHandler 21import org.mockftpserver.core.command.CommandNames 22import org.mockftpserver.core.session.StubSession 23import org.mockftpserver.core.session.SessionKeys 24import org.mockftpserver.fake.StubServerConfiguration 25import org.mockftpserver.fake.user.UserAccount 26import org.mockftpserver.core.command.ReplyCodes 27 28/** 29 * Tests for RnfrCommandHandler 30 * 31 * @version $Revision$ - $Date$ 32 * 33 * @author Chris Mair 34 */ 35class RnfrCommandHandlerTest extends AbstractLoginRequiredCommandHandlerTest { 36 37 def FILE = "/file.txt" 38 39 void testHandleCommand() { 40 assert fileSystem.createFile(FILE) 41 commandHandler.handleCommand(createCommand([FILE]), session) 42 assertSessionReply(ReplyCodes.RNFR_OK) 43 assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE 44 } 45 46 void testHandleCommand_PathIsRelative() { 47 assert fileSystem.createFile(FILE) 48 session.setAttribute(SessionKeys.CURRENT_DIRECTORY, "/") 49 commandHandler.handleCommand(createCommand(["file.txt"]), session) 50 assertSessionReply(ReplyCodes.RNFR_OK) 51 assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE 52 } 53 54 void testHandleCommand_PathDoesNotExistInFileSystem() { 55 commandHandler.handleCommand(createCommand([FILE]), session) 56 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE) 57 assert session.getAttribute(SessionKeys.RENAME_FROM) == null 58 } 59 60 void testHandleCommand_PathSpecifiesADirectory() { 61 assert fileSystem.createDirectory(FILE) 62 commandHandler.handleCommand(createCommand([FILE]), session) 63 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE) 64 assert session.getAttribute(SessionKeys.RENAME_FROM) == null 65 } 66 67 void testHandleCommand_MissingPathParameter() { 68 testHandleCommand_MissingRequiredParameter([]) 69 } 70 71 //------------------------------------------------------------------------- 72 // Helper Methods 73 //------------------------------------------------------------------------- 74 75 CommandHandler createCommandHandler() { 76 new RnfrCommandHandler() 77 } 78 79 Command createValidCommand() { 80 return new Command(CommandNames.RNFR, [FILE]) 81 } 82 83}