1/*
2 * Copyright 2007 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.Command;
19import org.mockftpserver.core.command.CommandNames;
20import org.mockftpserver.core.command.ReplyCodes;
21
22/**
23 * Tests for the SiteCommandHandler class
24 *
25 * @version $Revision$ - $Date$
26 *
27 * @author Chris Mair
28 */
29public final class SiteCommandHandlerTest extends AbstractCommandHandlerTest {
30
31    private static final String PARAMETERS1 = "abc def";
32    private static final String PARAMETERS2 = "abc,23,def";
33
34    private SiteCommandHandler commandHandler;
35    private Command command1;
36    private Command command2;
37
38    /**
39     * Test the handleCommand(Command,Session) method
40     * @throws Exception
41     */
42    public void testHandleCommand() throws Exception {
43        session.sendReply(ReplyCodes.SITE_OK, replyTextFor(ReplyCodes.SITE_OK));
44        session.sendReply(ReplyCodes.SITE_OK, replyTextFor(ReplyCodes.SITE_OK));
45        replay(session);
46
47        commandHandler.handleCommand(command1, session);
48        commandHandler.handleCommand(command2, session);
49        verify(session);
50
51        verifyNumberOfInvocations(commandHandler, 2);
52        verifyOneDataElement(commandHandler.getInvocation(0), SiteCommandHandler.PARAMETERS_KEY, PARAMETERS1);
53        verifyOneDataElement(commandHandler.getInvocation(1), SiteCommandHandler.PARAMETERS_KEY, PARAMETERS2);
54    }
55
56    /**
57     * Test the handleCommand() method, when no "parameters" parameter has been specified
58     */
59    public void testHandleCommand_MissingParameters() throws Exception {
60        testHandleCommand_InvalidParameters(commandHandler, CommandNames.SITE, EMPTY);
61    }
62
63    /**
64     * Perform initialization before each test
65     * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp()
66     */
67    protected void setUp() throws Exception {
68        super.setUp();
69        commandHandler = new SiteCommandHandler();
70        commandHandler.setReplyTextBundle(replyTextBundle);
71        command1 = new Command(CommandNames.SITE, array(PARAMETERS1));
72        command2 = new Command(CommandNames.SITE, array(PARAMETERS2));
73    }
74}
75