CwdCommandHandlerTest.groovy revision cb6dfe65d98c626326091432c4824764f38ab032
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.apache.log4j.Logger 27import org.mockftpserver.core.command.ReplyCodes 28 29/** 30 * Tests for CwdCommandHandler 31 * 32 * @version $Revision: $ - $Date: $ 33 * 34 * @author Chris Mair 35 */ 36class CwdCommandHandlerTest extends AbstractLoginRequiredCommandHandlerTest { 37 38 def DIR = "/usr" 39 40 void testHandleCommand() { 41 assert fileSystem.createDirectory(DIR) 42 commandHandler.handleCommand(createCommand([DIR]), session) 43 assertSessionReply(ReplyCodes.CWD_OK) 44 assert session.getAttribute(SessionKeys.CURRENT_DIRECTORY) == DIR 45 } 46 47 void testHandleCommand_PathIsRelative() { 48 def SUB = "sub" 49 assert fileSystem.createDirectory(p(DIR,SUB)) 50 session.setAttribute(SessionKeys.CURRENT_DIRECTORY, DIR) 51 commandHandler.handleCommand(createCommand([SUB]), session) 52 assertSessionReply(ReplyCodes.CWD_OK) 53 assert session.getAttribute(SessionKeys.CURRENT_DIRECTORY) == p(DIR,SUB) 54 } 55 56 void testHandleCommand_PathDoesNotExistInFileSystem() { 57 commandHandler.handleCommand(createCommand([DIR]), session) 58 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, DIR) 59 assert session.getAttribute(SessionKeys.CURRENT_DIRECTORY) == null 60 } 61 62 void testHandleCommand_PathSpecifiesAFile() { 63 assert fileSystem.createFile(DIR) 64 commandHandler.handleCommand(createCommand([DIR]), session) 65 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, DIR) 66 assert session.getAttribute(SessionKeys.CURRENT_DIRECTORY) == null 67 } 68 69 void testHandleCommand_MissingPathParameter() { 70 testHandleCommand_MissingRequiredParameter([]) 71 } 72 73 //------------------------------------------------------------------------- 74 // Helper Methods 75 //------------------------------------------------------------------------- 76 77 CommandHandler createCommandHandler() { 78 new CwdCommandHandler() 79 } 80 81 Command createValidCommand() { 82 return new Command(CommandNames.CWD, [DIR]) 83 } 84 85 void setUp() { 86 super.setUp() 87 } 88 89}