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