1a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon/*
2a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * Copyright 2007 the original author or authors.
3a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon *
4a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
5a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * you may not use this file except in compliance with the License.
6a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * You may obtain a copy of the License at
7a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon *
8a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
9a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon *
10a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * Unless required by applicable law or agreed to in writing, software
11a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
12a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * See the License for the specific language governing permissions and
14a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * limitations under the License.
15a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon */
16a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordonpackage org.mockftpserver.stub.command;
177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn
18a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordonimport org.mockftpserver.core.command.*;
19a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordonimport org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
20a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon
21a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon/**
22a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon * Tests for the AppeCommandHandler class
23a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon *
24d931a017a0abea32ad4485a91402b5f62b9ddb0eBrad Ebinger * @author Chris Mair
25d931a017a0abea32ad4485a91402b5f62b9ddb0eBrad Ebinger * @version $Revision$ - $Date$
26a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon */
27a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordonpublic final class AppeCommandHandlerTest extends AbstractCommandHandlerTestCase {
28a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon
29a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon    private AppeCommandHandler commandHandler;
30a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon
31d931a017a0abea32ad4485a91402b5f62b9ddb0eBrad Ebinger    /**
32a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon     * Perform initialization before each test
33a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon     *
34a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon     * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
35a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon     */
36a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon    protected void setUp() throws Exception {
37e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu        super.setUp();
38f62630a57de0d52be2bdbc92a9bf8f305cc0892dHall Liu        commandHandler = new AppeCommandHandler();
39abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad        commandHandler.setReplyTextBundle(replyTextBundle);
40a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon    }
41e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu
42f62630a57de0d52be2bdbc92a9bf8f305cc0892dHall Liu    /**
43f62630a57de0d52be2bdbc92a9bf8f305cc0892dHall Liu     * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods
44abcbce4441720c52a443d292d5adc2d95f446494Ihab Awad     */
45a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon    public void testHandleCommand() throws Exception {
46a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon        final String DATA = "ABC";
47e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu
48e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu        session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK));
49e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu        session.openDataConnection();
50e091ab90e37845cf4771051a6d2ce0ebadee4fe7Hall Liu        session.readData();
51d931a017a0abea32ad4485a91402b5f62b9ddb0eBrad Ebinger        control(session).setReturnValue(DATA.getBytes());
52f62630a57de0d52be2bdbc92a9bf8f305cc0892dHall Liu        session.closeDataConnection();
53f62630a57de0d52be2bdbc92a9bf8f305cc0892dHall Liu        session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK));
54a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon        replay(session);
55a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon
56a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon        Command command = new Command(CommandNames.APPE, array(FILENAME1));
57a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon        commandHandler.handleCommand(command, session);
58c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon        verify(session);
59c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon
60c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon        verifyNumberOfInvocations(commandHandler, 1);
61c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon        verifyTwoDataElements(commandHandler.getInvocation(0), AppeCommandHandler.PATHNAME_KEY, FILENAME1,
62c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon                AppeCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes());
63c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon    }
64c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon
65c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon    /**
66c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon     * Test the handleCommand() method, when no pathname parameter has been specified
67c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon     */
68c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon    public void testHandleCommand_MissingPathnameParameter() throws Exception {
69c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon        testHandleCommand_InvalidParameters(commandHandler, CommandNames.APPE, EMPTY);
70c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon    }
71c7b8ebabf904aa70a7a2a2a0ad01883088c56180Santos Cordon
7286014fcf9ec86e198a1ebac7c46e0e5c630735d7Tyler Gunn}
73a56f276cafcad80ab3a28996b6a0d72cffa4b2bcSantos Cordon