1c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/*
2c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Copyright 2008 the original author or authors.
3c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
4c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * you may not use this file except in compliance with the License.
6c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * You may obtain a copy of the License at
7c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
8c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
10c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Unless required by applicable law or agreed to in writing, software
11c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * See the License for the specific language governing permissions and
14c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * limitations under the License.
15c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */
16c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpackage org.mockftpserver.fake.command
17c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
18c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.Command
19c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.CommandHandler
20c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.CommandNames
21c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.core.command.ReplyCodes
22c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
23c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/**
24c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Tests for PortCommandHandler
25c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
26c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @version $Revision$ - $Date$
27c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair *
28c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @author Chris Mair
29c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */
30c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairclass PortCommandHandlerTest extends AbstractFakeCommandHandlerTest {
31c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
32c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    static final PARAMETERS = ["11", "22", "33", "44", "1", "206"]
33c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    static final PARAMETERS_INSUFFICIENT = ["7", "29", "99", "11", "77"]
34c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    static final PORT = (1 << 8) + 206
35c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    static final HOST = InetAddress.getByName("11.22.33.44")
36c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
37c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    boolean testNotLoggedIn = false
38c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
39c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    void testHandleCommand() {
40c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        handleCommand(PARAMETERS)
41c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        assertSessionReply(ReplyCodes.PORT_OK, 'port')
42c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        assert session.clientDataPort == PORT
43c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        assert session.clientDataHost == HOST
44c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
45c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
46c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    void testHandleCommand_MissingRequiredParameter() {
47c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        testHandleCommand_MissingRequiredParameter(PARAMETERS_INSUFFICIENT)
48c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
49c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
50c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    //-------------------------------------------------------------------------
51c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    // Helper Methods
52c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    //-------------------------------------------------------------------------
53c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
54c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    void setUp() {
55c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        super.setUp()
56c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
57c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
58c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    CommandHandler createCommandHandler() {
59c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        new PortCommandHandler()
60c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
61c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
62c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    Command createValidCommand() {
63c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair        return new Command(CommandNames.PORT, PARAMETERS)
64c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair    }
65c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair
66c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair}