RetrCommandHandlerTest.groovy revision 5e4167540f70a75ce28b9c69a41db7ee38c22de3
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.fake.filesystem.FileEntry 23 24 25/** 26 * Tests for RetrCommandHandler 27 * 28 * @version $Revision$ - $Date$ 29 * 30 * @author Chris Mair 31 */ 32class RetrCommandHandlerTest extends AbstractLoginRequiredCommandHandlerTest { 33 34 def DIR = "/" 35 def FILENAME = "file.txt" 36 def FILE = p(DIR, FILENAME) 37 def CONTENTS = "abc" 38 39 void testHandleCommand_MissingPathParameter() { 40 testHandleCommand_MissingRequiredParameter([]) 41 } 42 43 void testHandleCommand_AbsolutePath() { 44 handleCommandAndVerifySendDataReplies([FILE]) 45 assertSessionData(CONTENTS) 46 } 47 48 void testHandleCommand_RelativePath() { 49 setCurrentDirectory(DIR) 50 handleCommandAndVerifySendDataReplies([FILENAME]) 51 assertSessionData(CONTENTS) 52 } 53 54 void testHandleCommand_PathSpecifiesAnExistingDirectory() { 55 commandHandler.handleCommand(createCommand([DIR]), session) 56 assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, DIR) 57 } 58 59 void testHandleCommand_CreateInputStreamThrowsException() { 60 overrideMethodToThrowFileSystemException("createInputStream") 61 handleCommand([FILE]) 62 assertSessionReplies([ReplyCodes.TRANSFER_DATA_INITIAL_OK, ReplyCodes.EXISTING_FILE_ERROR]) 63 } 64 65 //------------------------------------------------------------------------- 66 // Helper Methods 67 //------------------------------------------------------------------------- 68 69 CommandHandler createCommandHandler() { 70 new RetrCommandHandler() 71 } 72 73 Command createValidCommand() { 74 return new Command(CommandNames.RETR, [FILE]) 75 } 76 77 void setUp() { 78 super.setUp() 79 assert fileSystem.createDirectory(DIR) 80 fileSystem.addEntry(new FileEntry(path: FILE, contents: CONTENTS)) 81 } 82 83}