177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/* 277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Copyright 2008 the original author or authors. 377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * you may not use this file except in compliance with the License. 677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * You may obtain a copy of the License at 777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * http://www.apache.org/licenses/LICENSE-2.0 977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 1077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Unless required by applicable law or agreed to in writing, software 1177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * See the License for the specific language governing permissions and 1477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * limitations under the License. 1577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 1677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpackage org.mockftpserver.fake.command 1777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 1877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.Command 1977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.CommandHandler 2077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.CommandNames 2177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.ReplyCodes 2277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 2377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/** 2477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Tests for StorCommandHandler 2577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 2677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @version $Revision$ - $Date$ 2777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 2877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @author Chris Mair 2977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 3077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairclass StorCommandHandlerTest extends AbstractStoreFileCommandHandlerTest { 3177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 3277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void testHandleCommand_MissingPathParameter() { 3377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair testHandleCommand_MissingRequiredParameter([]) 3477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 3577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 3677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void testHandleCommand_AbsolutePath() { 3777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair testHandleCommand([FILE], 'stor', CONTENTS) 3877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 3977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void testHandleCommand_RelativePath() { 4177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair setCurrentDirectory(DIR) 4277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair testHandleCommand([FILENAME], 'stor', CONTENTS) 4377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 4477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void testHandleCommand_PathSpecifiesAnExistingDirectory() { 4677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair createDirectory(FILE) 4777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair handleCommand([FILE]) 4877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair assertSessionReply(ReplyCodes.FILENAME_NOT_VALID, FILE) 4977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 5077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 5177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void testHandleCommand_ParentDirectoryDoesNotExist() { 5277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair def NO_SUCH_DIR = "/path/DoesNotExist" 5377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair handleCommand([p(NO_SUCH_DIR, FILENAME)]) 5477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair assertSessionReply(ReplyCodes.FILENAME_NOT_VALID, NO_SUCH_DIR) 5577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 5677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 5777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair //------------------------------------------------------------------------- 5877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair // Helper Methods 5977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair //------------------------------------------------------------------------- 6077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair CommandHandler createCommandHandler() { 6277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair new StorCommandHandler() 6377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 6477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair Command createValidCommand() { 6677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair return new Command(CommandNames.STOR, [FILE]) 6777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 6877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair void setUp() { 7077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair super.setUp() 7177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 7277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 7377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected String verifyOutputFile() { 7477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair assert fileSystem.isFile(FILE) 7577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair assert session.getReplyMessage(1).contains(FILENAME) 7677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair return FILE 7777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 7877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 7977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair}