PwdCommandHandlerTest.groovy revision 103f7abd5ad538f55215292e1460d8ef3bc46a4e
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
28
29/**
30 * Tests for PwdCommandHandler
31 *
32 * @version $Revision: $ - $Date: $
33 *
34 * @author Chris Mair
35 */
36class PwdCommandHandlerTest extends AbstractFakeCommandHandlerTest {
37
38    def DIR = "/usr/abc"
39
40    void testHandleCommand() {
41        session.setAttribute(SessionKeys.CURRENT_DIRECTORY, DIR)
42        serverConfiguration.setTextForReplyCode(ReplyCodes.PWD_OK, "dir={0}")
43        commandHandler.handleCommand(createCommand([]), session)
44        assertSessionReply(ReplyCodes.PWD_OK, "dir=${DIR}")
45	}
46
47    void testHandleCommand_CurrentDirectoryNotSet() {
48		commandHandler.handleCommand(createValidCommand(), session)
49        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR)
50    }
51
52    //-------------------------------------------------------------------------
53    // Helper Methods
54    //-------------------------------------------------------------------------
55
56    void setUp() {
57        super.setUp()
58    }
59
60    CommandHandler createCommandHandler() {
61	    new PwdCommandHandler()
62	}
63
64    Command createValidCommand() {
65        return new Command(CommandNames.PWD, [])
66    }
67
68}