PwdCommandHandlerTest.groovy revision 016b6dd21f1a552e28f4c6894b586b770241b0ed
1/*
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.fake.command
17
18import org.mockftpserver.test.AbstractGroovyTest
19import org.mockftpserver.core.command.Command
20import org.mockftpserver.core.command.CommandHandler
21import org.mockftpserver.core.command.CommandNames
22import org.mockftpserver.core.session.StubSession
23import org.mockftpserver.core.session.SessionKeys
24import org.mockftpserver.fake.StubServerConfiguration
25import org.mockftpserver.fake.user.UserAccount
26import org.apache.log4j.Logger
27import org.mockftpserver.core.command.ReplyCodes
28import org.mockftpserver.core.util.AssertFailedException
29
30/**
31 * Tests for PwdCommandHandler
32 *
33 * @version $Revision: $ - $Date: $
34 *
35 * @author Chris Mair
36 */
37class PwdCommandHandlerTest extends AbstractFakeCommandHandlerTest {
38
39    def DIR = "/usr/abc"
40
41    void testHandleCommand() {
42        session.setAttribute(SessionKeys.CURRENT_DIRECTORY, DIR)
43        serverConfiguration.setTextForReplyCode(ReplyCodes.PWD_OK, "dir={0}")
44        commandHandler.handleCommand(createCommand([]), session)
45        assertSessionReply(ReplyCodes.PWD_OK, "dir=${DIR}")
46	}
47
48    void testHandleCommand_CurrentDirectoryNotSet() {
49		commandHandler.handleCommand(createValidCommand(), session)
50        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR)
51    }
52
53    //-------------------------------------------------------------------------
54    // Helper Methods
55    //-------------------------------------------------------------------------
56
57    void setUp() {
58        super.setUp()
59        this.commandHandlerRequiresLogin = false
60    }
61
62    CommandHandler createCommandHandler() {
63	    new PwdCommandHandler()
64	}
65
66    Command createValidCommand() {
67        return new Command(CommandNames.PWD, [])
68    }
69
70}