blob: 6f5f4e049d1ee2ad4cd95a71a879a724497db6b2 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
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.stub.command;
17
18import org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
19import org.mockftpserver.core.command.Command;
20import org.mockftpserver.core.command.CommandNames;
21import org.mockftpserver.core.command.ReplyCodes;
22
23import java.net.InetAddress;
24
25/**
26 * Tests for the PortCommandHandler class
27 *
28 * @author Chris Mair
29 * @version $Revision$ - $Date$
30 */
31public final class PortCommandHandlerTest extends AbstractCommandHandlerTestCase {
32
33 private static final String[] PARAMETERS = new String[]{"11", "22", "33", "44", "1", "206"};
34 private static final String[] PARAMETERS_INSUFFICIENT = new String[]{"7", "29", "99", "11", "77"};
35 private static final int PORT = (1 << 8) + 206;
36 private static final InetAddress HOST = inetAddress("11.22.33.44");
37
38 private PortCommandHandler commandHandler;
39
40 /**
41 * Test the handleCommand() method
42 */
43 public void testHandleCommand() throws Exception {
44 final Command COMMAND = new Command(CommandNames.PORT, PARAMETERS);
45
46 session.setClientDataPort(PORT);
47 session.setClientDataHost(HOST);
48 session.sendReply(ReplyCodes.PORT_OK, replyTextFor(ReplyCodes.PORT_OK));
49 replay(session);
50
51 commandHandler.handleCommand(COMMAND, session);
52 verify(session);
53
54 verifyNumberOfInvocations(commandHandler, 1);
55 verifyTwoDataElements(commandHandler.getInvocation(0),
56 PortCommandHandler.HOST_KEY, HOST,
57 PortCommandHandler.PORT_KEY, new Integer(PORT));
58 }
59
60 /**
61 * Test the handleCommand() method, when not enough parameters have been specified
62 */
63 public void testHandleCommand_InsufficientParameters() throws Exception {
64 testHandleCommand_InvalidParameters(commandHandler, CommandNames.PORT, PARAMETERS_INSUFFICIENT);
65 }
66
67 /**
68 * Perform initialization before each test
69 *
70 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
71 */
72 protected void setUp() throws Exception {
73 super.setUp();
74 commandHandler = new PortCommandHandler();
75 commandHandler.setReplyTextBundle(replyTextBundle);
76 }
77
78}