StatCommandHandlerTest.java revision 93102446a7b7c3d17888064b4e2e4e5cb534e6d0
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; 21import org.mockftpserver.stub.command.StatCommandHandler; 22 23/** 24 * Tests for the StatCommandHandler class 25 * 26 * @version $Revision: 88 $ - $Date: 2007-10-27 20:18:11 -0400 (Sat, 27 Oct 2007) $ 27 * 28 * @author Chris Mair 29 */ 30public final class StatCommandHandlerTest extends AbstractCommandHandlerTest { 31 32 private static final String RESPONSE_DATA = "status info 123.456"; 33 private static final String PATHNAME = "dir/file"; 34 35 private StatCommandHandler commandHandler; 36 37 /** 38 * Test the handleCommand() method, when no pathname parameter is specified 39 */ 40 public void testHandleCommand_NoPathname() throws Exception { 41 42 session.sendReply(ReplyCodes.STAT_SYSTEM_OK, formattedReplyTextFor(ReplyCodes.STAT_SYSTEM_OK, RESPONSE_DATA)); 43 replay(session); 44 45 final Command COMMAND = new Command(CommandNames.STAT, EMPTY); 46 commandHandler.setStatus(RESPONSE_DATA); 47 commandHandler.handleCommand(COMMAND, session); 48 verify(session); 49 50 verifyNumberOfInvocations(commandHandler, 1); 51 verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, null); 52 } 53 54 /** 55 * Test the handleCommand() method, specifying a pathname parameter 56 * @throws Exception 57 */ 58 public void testHandleCommand_Pathname() throws Exception { 59 60 session.sendReply(ReplyCodes.STAT_FILE_OK, formattedReplyTextFor(ReplyCodes.STAT_FILE_OK, RESPONSE_DATA)); 61 replay(session); 62 63 final Command COMMAND = new Command(CommandNames.STAT, array(PATHNAME)); 64 65 commandHandler.setStatus(RESPONSE_DATA); 66 commandHandler.handleCommand(COMMAND, session); 67 verify(session); 68 69 verifyNumberOfInvocations(commandHandler, 1); 70 verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, PATHNAME); 71 } 72 73 /** 74 * Test the handleCommand() method, when the replyCode is explicitly set 75 */ 76 public void testHandleCommand_OverrideReplyCode() throws Exception { 77 78 session.sendReply(200, replyTextFor(200)); 79 replay(session); 80 81 final Command COMMAND = new Command(CommandNames.STAT, EMPTY); 82 commandHandler.setStatus(RESPONSE_DATA); 83 commandHandler.setReplyCode(200); 84 commandHandler.handleCommand(COMMAND, session); 85 86 verify(session); 87 88 verifyNumberOfInvocations(commandHandler, 1); 89 verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, null); 90 } 91 92 /** 93 * Perform initialization before each test 94 * 95 * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp() 96 */ 97 protected void setUp() throws Exception { 98 super.setUp(); 99 commandHandler = new StatCommandHandler(); 100 commandHandler.setReplyTextBundle(replyTextBundle); 101 } 102 103} 104