StorCommandHandlerTest.java revision 5e4167540f70a75ce28b9c69a41db7ee38c22de3
1/* 2 * Copyright 2007 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.stub.command; 17 18import org.mockftpserver.core.command.Command; 19import org.mockftpserver.core.command.CommandNames; 20import org.mockftpserver.core.command.ReplyCodes; 21 22/** 23 * Tests for the StorCommandHandler class 24 * 25 * @author Chris Mair 26 * @version $Revision$ - $Date$ 27 */ 28public final class StorCommandHandlerTest extends AbstractCommandHandlerTest { 29 30 private StorCommandHandler commandHandler; 31 32 /** 33 * Perform initialization before each test 34 * 35 * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp() 36 */ 37 protected void setUp() throws Exception { 38 super.setUp(); 39 commandHandler = new StorCommandHandler(); 40 commandHandler.setReplyTextBundle(replyTextBundle); 41 } 42 43 /** 44 * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 45 */ 46 public void testHandleCommand() throws Exception { 47 final String DATA = "ABC"; 48 49 session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK)); 50 session.openDataConnection(); 51 session.readData(); 52 control(session).setReturnValue(DATA.getBytes()); 53 session.closeDataConnection(); 54 session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK)); 55 replay(session); 56 57 Command command = new Command(CommandNames.STOR, array(FILENAME1)); 58 commandHandler.handleCommand(command, session); 59 verify(session); 60 61 verifyNumberOfInvocations(commandHandler, 1); 62 verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1, 63 StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 64 } 65 66 /** 67 * Test the handleCommand() method, when no pathname parameter has been specified 68 */ 69 public void testHandleCommand_MissingPathnameParameter() throws Exception { 70 testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY); 71 } 72 73} 74