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