PortCommandHandlerTest.groovy revision 6fed98e9c695a9024ede347900c2689979ab5785
1/* 2 * Copyright 2008 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.fake.command 17 18import org.mockftpserver.core.command.Command 19import org.mockftpserver.core.command.CommandHandler 20import org.mockftpserver.core.command.CommandNames 21import org.mockftpserver.core.command.ReplyCodes 22 23/** 24 * Tests for PortCommandHandler 25 * 26 * @version $Revision$ - $Date$ 27 * 28 * @author Chris Mair 29 */ 30class PortCommandHandlerTest extends AbstractFakeCommandHandlerTest { 31 32 static final PARAMETERS = ["11", "22", "33", "44", "1", "206"] 33 static final PARAMETERS_INSUFFICIENT = ["7", "29", "99", "11", "77"] 34 static final PORT = (1 << 8) + 206 35 static final HOST = InetAddress.getByName("11.22.33.44") 36 37 void testHandleCommand() { 38 commandHandler.handleCommand(createCommand(PARAMETERS), session) 39 assertSessionReply(ReplyCodes.PORT_OK, 'port') 40 assert session.clientDataPort == PORT 41 assert session.clientDataHost == HOST 42 } 43 44 void testHandleCommand_MissingRequiredParameter() { 45 testHandleCommand_MissingRequiredParameter(PARAMETERS_INSUFFICIENT) 46 } 47 48 //------------------------------------------------------------------------- 49 // Helper Methods 50 //------------------------------------------------------------------------- 51 52 void setUp() { 53 super.setUp() 54 } 55 56 CommandHandler createCommandHandler() { 57 new PortCommandHandler() 58 } 59 60 Command createValidCommand() { 61 return new Command(CommandNames.PORT, PARAMETERS) 62 } 63 64}