RnfrCommandHandlerTest.groovy revision 103f7abd5ad538f55215292e1460d8ef3bc46a4e
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_PathDoesNotExistInFileSystem() { 47 commandHandler.handleCommand(createCommand([FILE]), session) 48 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE) 49 assert session.getAttribute(SessionKeys.RENAME_FROM) == null 50 } 51 52 void testHandleCommand_PathSpecifiesADirectory() { 53 assert fileSystem.createDirectory(FILE) 54 commandHandler.handleCommand(createCommand([FILE]), session) 55 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE) 56 assert session.getAttribute(SessionKeys.RENAME_FROM) == null 57 } 58 59 void testHandleCommand_MissingPathParameter() { 60 testHandleCommand_MissingRequiredParameter([]) 61 } 62 63 //------------------------------------------------------------------------- 64 // Helper Methods 65 //------------------------------------------------------------------------- 66 67 CommandHandler createCommandHandler() { 68 new RnfrCommandHandler() 69 } 70 71 Command createValidCommand() { 72 return new Command(CommandNames.RNFR, [FILE]) 73 } 74 75}