1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/* 2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2009 the original author or authors. 3bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License. 6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at 7bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 8bda3441225e0607b5ced8b538123fd7c7a417910chrismair * http://www.apache.org/licenses/LICENSE-2.0 9bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software 11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and 14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License. 15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.stub.command; 17bda3441225e0607b5ced8b538123fd7c7a417910chrismair 18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.*; 19bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.core.command.AbstractCommandHandlerTestCase; 20bda3441225e0607b5ced8b538123fd7c7a417910chrismair 21bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport java.net.InetAddress; 22bda3441225e0607b5ced8b538123fd7c7a417910chrismair 23bda3441225e0607b5ced8b538123fd7c7a417910chrismair/** 24bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Tests for the EprtCommandHandler class 25bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 26bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair 27bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$ 28bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 29bda3441225e0607b5ced8b538123fd7c7a417910chrismairpublic final class EprtCommandHandlerTest extends AbstractCommandHandlerTestCase { 30bda3441225e0607b5ced8b538123fd7c7a417910chrismair 31bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final String[] PARAMETERS_INSUFFICIENT = EMPTY; 32bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final String[] PARAMETERS_IPV4 = {"|1|132.235.1.2|6275|"}; 33bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final InetAddress HOST_IPV4 = inetAddress("132.235.1.2"); 34bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final String[] PARAMETERS_IPV6 = {"|2|1080::8:800:200C:417A|6275|"}; 35bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final InetAddress HOST_IPV6 = inetAddress("1080::8:800:200C:417A"); 36bda3441225e0607b5ced8b538123fd7c7a417910chrismair private static final int PORT = 6275; 37bda3441225e0607b5ced8b538123fd7c7a417910chrismair 38bda3441225e0607b5ced8b538123fd7c7a417910chrismair private EprtCommandHandler commandHandler; 39bda3441225e0607b5ced8b538123fd7c7a417910chrismair 40bda3441225e0607b5ced8b538123fd7c7a417910chrismair public void testHandleCommand_IPv4() throws Exception { 41bda3441225e0607b5ced8b538123fd7c7a417910chrismair final Command COMMAND = new Command(CommandNames.EPRT, PARAMETERS_IPV4); 42bda3441225e0607b5ced8b538123fd7c7a417910chrismair 43bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataPort(PORT); 44bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataHost(HOST_IPV4); 45bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.sendReply(ReplyCodes.EPRT_OK, replyTextFor(ReplyCodes.EPRT_OK)); 46bda3441225e0607b5ced8b538123fd7c7a417910chrismair replay(session); 47bda3441225e0607b5ced8b538123fd7c7a417910chrismair 48bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler.handleCommand(COMMAND, session); 49bda3441225e0607b5ced8b538123fd7c7a417910chrismair verify(session); 50bda3441225e0607b5ced8b538123fd7c7a417910chrismair 51bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyNumberOfInvocations(commandHandler, 1); 52bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyTwoDataElements(commandHandler.getInvocation(0), 53bda3441225e0607b5ced8b538123fd7c7a417910chrismair PortCommandHandler.HOST_KEY, HOST_IPV4, 54bda3441225e0607b5ced8b538123fd7c7a417910chrismair PortCommandHandler.PORT_KEY, new Integer(PORT)); 55bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 56bda3441225e0607b5ced8b538123fd7c7a417910chrismair 57bda3441225e0607b5ced8b538123fd7c7a417910chrismair public void testHandleCommand_IPv6() throws Exception { 58bda3441225e0607b5ced8b538123fd7c7a417910chrismair final Command COMMAND = new Command(CommandNames.EPRT, PARAMETERS_IPV6); 59bda3441225e0607b5ced8b538123fd7c7a417910chrismair 60bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataPort(PORT); 61bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.setClientDataHost(HOST_IPV6); 62bda3441225e0607b5ced8b538123fd7c7a417910chrismair session.sendReply(ReplyCodes.EPRT_OK, replyTextFor(ReplyCodes.EPRT_OK)); 63bda3441225e0607b5ced8b538123fd7c7a417910chrismair replay(session); 64bda3441225e0607b5ced8b538123fd7c7a417910chrismair 65bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler.handleCommand(COMMAND, session); 66bda3441225e0607b5ced8b538123fd7c7a417910chrismair verify(session); 67bda3441225e0607b5ced8b538123fd7c7a417910chrismair 68bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyNumberOfInvocations(commandHandler, 1); 69bda3441225e0607b5ced8b538123fd7c7a417910chrismair verifyTwoDataElements(commandHandler.getInvocation(0), 70bda3441225e0607b5ced8b538123fd7c7a417910chrismair PortCommandHandler.HOST_KEY, HOST_IPV6, 71bda3441225e0607b5ced8b538123fd7c7a417910chrismair PortCommandHandler.PORT_KEY, new Integer(PORT)); 72bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 73bda3441225e0607b5ced8b538123fd7c7a417910chrismair 74bda3441225e0607b5ced8b538123fd7c7a417910chrismair public void testHandleCommand_MissingRequiredParameter() throws Exception { 75bda3441225e0607b5ced8b538123fd7c7a417910chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.EPRT, PARAMETERS_INSUFFICIENT); 76bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 77bda3441225e0607b5ced8b538123fd7c7a417910chrismair 78bda3441225e0607b5ced8b538123fd7c7a417910chrismair /** 79bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Perform initialization before each test 80bda3441225e0607b5ced8b538123fd7c7a417910chrismair * 81bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp() 82bda3441225e0607b5ced8b538123fd7c7a417910chrismair */ 83bda3441225e0607b5ced8b538123fd7c7a417910chrismair protected void setUp() throws Exception { 84bda3441225e0607b5ced8b538123fd7c7a417910chrismair super.setUp(); 85bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler = new EprtCommandHandler(); 86bda3441225e0607b5ced8b538123fd7c7a417910chrismair commandHandler.setReplyTextBundle(replyTextBundle); 87bda3441225e0607b5ced8b538123fd7c7a417910chrismair } 88bda3441225e0607b5ced8b538123fd7c7a417910chrismair 89bda3441225e0607b5ced8b538123fd7c7a417910chrismair}