1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/* 2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2007 the original author or authors. 3bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License. 6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at 7bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 8bda3441225e0607b5ced8b538123fd7c7a417910chrismair * http://www.apache.org/licenses/LICENSE-2.0 9bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software 11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and 14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License. 15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.stub.command; 17bda3441225e0607b5ced8b538123fd7c7a417910chrismair 18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.*; 19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.AbstractCommandHandlerTestCase; 20bda3441225e0607b5ced8b538123fd7c7a417910chrismair 21bda3441225e0607b5ced8b538123fd7c7a417910chrismair/** 22bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Tests for the StorCommandHandler class 23bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 24bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair 25bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$ 26bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 27bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic final class StorCommandHandlerTest extends AbstractCommandHandlerTestCase { 28bda3441225e0607b5ced8b538123fd7c7a417910chrismair 29bda3441225e0607b5ced8b538123fd7c7a417910chrismair private StorCommandHandler commandHandler; 30bda3441225e0607b5ced8b538123fd7c7a417910chrismair 31bda3441225e0607b5ced8b538123fd7c7a417910chrismair /** 32bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Perform initialization before each test 33bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 34bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp() 35bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 36bda3441225e0607b5ced8b538123fd7c7a417910chrismair protected void setUp() throws Exception { 37bda3441225e0607b5ced8b538123fd7c7a417910chrismair super.setUp(); 38bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler = new StorCommandHandler(); 39bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler.setReplyTextBundle(replyTextBundle); 40bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 41bda3441225e0607b5ced8b538123fd7c7a417910chrismair 42bda3441225e0607b5ced8b538123fd7c7a417910chrismair /** 43bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 44bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 45bda3441225e0607b5ced8b538123fd7c7a417910chrismair public void testHandleCommand() throws Exception { 46bda3441225e0607b5ced8b538123fd7c7a417910chrismair final String DATA = "ABC"; 47bda3441225e0607b5ced8b538123fd7c7a417910chrismair 48bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK)); 49bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.openDataConnection(); 50bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.readData(); 51bda3441225e0607b5ced8b538123fd7c7a417910chrismair control(session).setReturnValue(DATA.getBytes()); 52bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.closeDataConnection(); 53bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK)); 54bda3441225e0607b5ced8b538123fd7c7a417910chrismair replay(session); 55bda3441225e0607b5ced8b538123fd7c7a417910chrismair 56bda3441225e0607b5ced8b538123fd7c7a417910chrismair Command command = new Command(CommandNames.STOR, array(FILENAME1)); 57bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler.handleCommand(command, session); 58bda3441225e0607b5ced8b538123fd7c7a417910chrismair verify(session); 59bda3441225e0607b5ced8b538123fd7c7a417910chrismair 60bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyNumberOfInvocations(commandHandler, 1); 61bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1, 62bda3441225e0607b5ced8b538123fd7c7a417910chrismair StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 63bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 64bda3441225e0607b5ced8b538123fd7c7a417910chrismair 65bda3441225e0607b5ced8b538123fd7c7a417910chrismair /** 66bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Test the handleCommand() method, when no pathname parameter has been specified 67bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 68bda3441225e0607b5ced8b538123fd7c7a417910chrismair public void testHandleCommand_MissingPathnameParameter() throws Exception { 69bda3441225e0607b5ced8b538123fd7c7a417910chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY); 70bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 71bda3441225e0607b5ced8b538123fd7c7a417910chrismair 72bda3441225e0607b5ced8b538123fd7c7a417910chrismair} 73