PwdCommandHandlerTest.groovy revision ae0aaa3a69844af9a57ec1e0219adba82c9919d3
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        testHandleCommand_MissingRequiredSessionAttribute()
50    }
51
52    //-------------------------------------------------------------------------
53    // Helper Methods
54    //-------------------------------------------------------------------------
55
56	CommandHandler createCommandHandler() {
57	    new PwdCommandHandler()
58	}
59
60    Command createValidCommand() {
61        return new Command(CommandNames.PWD, [])
62    }
63
64}