177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/* 277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Copyright 2007 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.stub.command; 1777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 1877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.AbstractCommandHandlerTest; 1977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.Command; 2077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.CommandNames; 2177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.core.command.ReplyCodes; 2277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 2377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/** 2477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Tests for the StorCommandHandler class 2577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 2677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @author Chris Mair 2777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @version $Revision$ - $Date$ 2877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 2977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpublic final class StorCommandHandlerTest extends AbstractCommandHandlerTest { 3077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 3177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair private StorCommandHandler commandHandler; 3277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 3377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 3477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Perform initialization before each test 3577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * 3677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * @see org.mockftpserver.core.command.AbstractCommandHandlerTest#setUp() 3777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 3877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair protected void setUp() throws Exception { 3977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair super.setUp(); 4077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair commandHandler = new StorCommandHandler(); 4177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair commandHandler.setReplyTextBundle(replyTextBundle); 4277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 4377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 4477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 4577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 4677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 4777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair public void testHandleCommand() throws Exception { 4877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair final String DATA = "ABC"; 4977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 5077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK)); 5177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair session.openDataConnection(); 5277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair session.readData(); 5377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair control(session).setReturnValue(DATA.getBytes()); 5477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair session.closeDataConnection(); 5577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK)); 5677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair replay(session); 5777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 5877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair Command command = new Command(CommandNames.STOR, array(FILENAME1)); 5977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair commandHandler.handleCommand(command, session); 6077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair verify(session); 6177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair verifyNumberOfInvocations(commandHandler, 1); 6377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1, 6477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 6577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 6677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 6777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair /** 6877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Test the handleCommand() method, when no pathname parameter has been specified 6977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */ 7077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair public void testHandleCommand_MissingPathnameParameter() throws Exception { 7177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY); 7277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair } 7377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair 7477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair} 75