MkdCommandHandlerTest.groovy revision 777c1c842d19df00d2529ccf43e4f4c26cfd39fb
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 23 24/** 25 * Tests for MkdCommandHandler 26 * 27 * @version $Revision$ - $Date$ 28 * 29 * @author Chris Mair 30 */ 31class MkdCommandHandlerTest extends AbstractLoginRequiredCommandHandlerTest { 32 33 def DIRNAME = "usr" 34 def DIR = p('/', DIRNAME) 35 36 void testHandleCommand() { 37 commandHandler.handleCommand(createCommand([DIR]), session) 38 assertSessionReply(ReplyCodes.MKD_OK, ['mkd', DIR]) 39 assert fileSystem.exists(DIR) 40 } 41 42 void testHandleCommand_PathIsRelative() { 43 session.setAttribute(SessionKeys.CURRENT_DIRECTORY, '/') 44 commandHandler.handleCommand(createCommand([DIRNAME]), session) 45 assertSessionReply(ReplyCodes.MKD_OK, ['mkd', DIRNAME]) 46 assert fileSystem.exists(DIR) 47 } 48 49 void testHandleCommand_ParentDirectoryDoesNotExist() { 50 commandHandler.handleCommand(createCommand(['/abc/def']), session) 51 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, ['filesystem.doesNotExist', '/abc']) 52 } 53 54 void testHandleCommand_PathSpecifiesAFile() { 55 assert fileSystem.createFile(DIR) 56 commandHandler.handleCommand(createCommand([DIR]), session) 57 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, ['filesystem.alreadyExists', DIR]) 58 assert fileSystem.exists(DIR) 59 } 60 61 void testHandleCommand_MissingPathParameter() { 62 testHandleCommand_MissingRequiredParameter([]) 63 } 64 65 void testHandleCommand_CreateDirectoryThrowsException() { 66 overrideMethodToThrowFileSystemException("createDirectory") 67 handleCommand([DIR]) 68 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, ERROR_MESSAGE_KEY) 69 } 70 71 void setUp() { 72 super.setUp() 73 fileSystem.createDirectory('/') 74 } 75 76 //------------------------------------------------------------------------- 77 // Helper Methods 78 //------------------------------------------------------------------------- 79 80 CommandHandler createCommandHandler() { 81 new MkdCommandHandler() 82 } 83 84 Command createValidCommand() { 85 return new Command(CommandNames.MKD, [DIR]) 86 } 87 88}