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.slf4j.Logger; 19import org.slf4j.LoggerFactory; 20import org.mockftpserver.core.command.AbstractCommandHandlerTestCase; 21import org.mockftpserver.core.command.Command; 22import org.mockftpserver.core.command.CommandNames; 23import org.mockftpserver.core.command.ReplyCodes; 24 25import java.net.InetAddress; 26 27/** 28 * Tests for the PasvCommandHandler class 29 * 30 * @author Chris Mair 31 * @version $Revision$ - $Date$ 32 */ 33public final class PasvCommandHandlerTest extends AbstractCommandHandlerTestCase { 34 35 private static final Logger LOG = LoggerFactory.getLogger(PasvCommandHandlerTest.class); 36 private static final int PORT = (23 << 8) + 77; 37 38 private PasvCommandHandler commandHandler; 39 40 /** 41 * Test the handleCommand() method 42 */ 43 public void testHandleCommand() throws Exception { 44 45 final InetAddress SERVER = inetAddress("192.168.0.2"); 46 session.switchToPassiveMode(); 47 control(session).setReturnValue(PORT); 48 session.getServerHost(); 49 control(session).setReturnValue(SERVER); 50 session.sendReply(ReplyCodes.PASV_OK, formattedReplyTextFor(227, "(192,168,0,2,23,77)")); 51 replay(session); 52 53 final Command COMMAND = new Command(CommandNames.PASV, EMPTY); 54 55 commandHandler.handleCommand(COMMAND, session); 56 verify(session); 57 58 verifyNumberOfInvocations(commandHandler, 1); 59 verifyNoDataElements(commandHandler.getInvocation(0)); 60 } 61 62 /** 63 * Perform initialization before each test 64 * 65 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp() 66 */ 67 protected void setUp() throws Exception { 68 super.setUp(); 69 commandHandler = new PasvCommandHandler(); 70 commandHandler.setReplyTextBundle(replyTextBundle); 71 } 72 73} 74