blob: 632fa5965046d9205667a481af99868466912735 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
2 * Copyright 2009 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.*;
19import org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
20
21import java.net.InetAddress;
22
23/**
24 * Tests for the EprtCommandHandler class
25 *
26 * @author Chris Mair
27 * @version $Revision$ - $Date$
28 */
29public final class EprtCommandHandlerTest extends AbstractCommandHandlerTestCase {
30
31 private static final String[] PARAMETERS_INSUFFICIENT = EMPTY;
32 private static final String[] PARAMETERS_IPV4 = {"|1|132.235.1.2|6275|"};
33 private static final InetAddress HOST_IPV4 = inetAddress("132.235.1.2");
34 private static final String[] PARAMETERS_IPV6 = {"|2|1080::8:800:200C:417A|6275|"};
35 private static final InetAddress HOST_IPV6 = inetAddress("1080::8:800:200C:417A");
36 private static final int PORT = 6275;
37
38 private EprtCommandHandler commandHandler;
39
40 public void testHandleCommand_IPv4() throws Exception {
41 final Command COMMAND = new Command(CommandNames.EPRT, PARAMETERS_IPV4);
42
43 session.setClientDataPort(PORT);
44 session.setClientDataHost(HOST_IPV4);
45 session.sendReply(ReplyCodes.EPRT_OK, replyTextFor(ReplyCodes.EPRT_OK));
46 replay(session);
47
48 commandHandler.handleCommand(COMMAND, session);
49 verify(session);
50
51 verifyNumberOfInvocations(commandHandler, 1);
52 verifyTwoDataElements(commandHandler.getInvocation(0),
53 PortCommandHandler.HOST_KEY, HOST_IPV4,
54 PortCommandHandler.PORT_KEY, new Integer(PORT));
55 }
56
57 public void testHandleCommand_IPv6() throws Exception {
58 final Command COMMAND = new Command(CommandNames.EPRT, PARAMETERS_IPV6);
59
60 session.setClientDataPort(PORT);
61 session.setClientDataHost(HOST_IPV6);
62 session.sendReply(ReplyCodes.EPRT_OK, replyTextFor(ReplyCodes.EPRT_OK));
63 replay(session);
64
65 commandHandler.handleCommand(COMMAND, session);
66 verify(session);
67
68 verifyNumberOfInvocations(commandHandler, 1);
69 verifyTwoDataElements(commandHandler.getInvocation(0),
70 PortCommandHandler.HOST_KEY, HOST_IPV6,
71 PortCommandHandler.PORT_KEY, new Integer(PORT));
72 }
73
74 public void testHandleCommand_MissingRequiredParameter() throws Exception {
75 testHandleCommand_InvalidParameters(commandHandler, CommandNames.EPRT, PARAMETERS_INSUFFICIENT);
76 }
77
78 /**
79 * Perform initialization before each test
80 *
81 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
82 */
83 protected void setUp() throws Exception {
84 super.setUp();
85 commandHandler = new EprtCommandHandler();
86 commandHandler.setReplyTextBundle(replyTextBundle);
87 }
88
89}