RnfrCommandHandlerTest.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 RnfrCommandHandler
32 *
33 * @version $Revision: $ - $Date: $
34 *
35 * @author Chris Mair
36 */
37class RnfrCommandHandlerTest extends AbstractFakeCommandHandlerTest {
38
39    def FILE = "/file.txt"
40
41    void testHandleCommand() {
42        assert fileSystem.createFile(FILE)
43        commandHandler.handleCommand(createCommand([FILE]), session)
44        assertSessionReply(ReplyCodes.RNFR_OK)
45        assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE
46	}
47
48    void testHandleCommand_PathDoesNotExistInFileSystem() {
49        commandHandler.handleCommand(createCommand([FILE]), session)
50        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE)
51        assert session.getAttribute(SessionKeys.RENAME_FROM) == null
52	}
53
54    void testHandleCommand_PathSpecifiesADirectory() {
55        assert fileSystem.createDirectory(FILE)
56        commandHandler.handleCommand(createCommand([FILE]), session)
57        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE)
58        assert session.getAttribute(SessionKeys.RENAME_FROM) == null
59	}
60
61    void testHandleCommand_MissingPathParameter() {
62        testHandleCommand_MissingRequiredParameter([])
63    }
64
65    //-------------------------------------------------------------------------
66    // Helper Methods
67    //-------------------------------------------------------------------------
68
69	CommandHandler createCommandHandler() {
70	    new RnfrCommandHandler()
71	}
72
73    Command createValidCommand() {
74        return new Command(CommandNames.RNFR, [FILE])
75    }
76
77    void setUp() {
78        super.setUp()
79        session.setAttribute(SessionKeys.USER_ACCOUNT, userAccount)
80    }
81
82}