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 */ 16 package org.mockftpserver.stub.command; 17 18 import org.mockftpserver.core.command.AbstractCommandHandlerTestCase; 19 import org.mockftpserver.core.command.Command; 20 import org.mockftpserver.core.command.CommandNames; 21 import org.mockftpserver.core.command.ReplyCodes; 22 23 /** 24 * Tests for the StouCommandHandler class 25 * 26 * @author Chris Mair 27 * @version $Revision$ - $Date$ 28 */ 29 public final class StouCommandHandlerTest extends AbstractCommandHandlerTestCase { 30 31 private StouCommandHandler commandHandler; 32 33 /** 34 * Perform initialization before each test 35 * 36 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp() 37 */ 38 protected void setUp() throws Exception { 39 super.setUp(); 40 commandHandler = new StouCommandHandler(); 41 commandHandler.setReplyTextBundle(replyTextBundle); 42 } 43 44 /** 45 * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 46 */ 47 public void testHandleCommand() throws Exception { 48 final String DATA = "ABC"; 49 final String FILENAME = "abc.txt"; 50 51 session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK)); 52 session.openDataConnection(); 53 session.readData(); 54 control(session).setReturnValue(DATA.getBytes()); 55 session.closeDataConnection(); 56 session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, formattedReplyTextFor("226.WithFilename", FILENAME)); 57 replay(session); 58 59 Command command = new Command(CommandNames.STOU, array(FILENAME1)); 60 commandHandler.setFilename(FILENAME); 61 commandHandler.handleCommand(command, session); 62 verify(session); 63 64 verifyNumberOfInvocations(commandHandler, 1); 65 verifyOneDataElement(commandHandler.getInvocation(0), StouCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 66 } 67 68 } 69