RnfrCommandHandlerTest.groovy revision 9b31560d2bb49af587fe31dbc4f272d726eec298
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.core.command.Command
19import org.mockftpserver.core.command.CommandHandler
20import org.mockftpserver.core.command.CommandNames
21import org.mockftpserver.core.command.ReplyCodes
22import org.mockftpserver.core.session.SessionKeys
23
24/**
25 * Tests for RnfrCommandHandler
26 *
27 * @version $Revision$ - $Date$
28 *
29 * @author Chris Mair
30 */
31class RnfrCommandHandlerTest extends AbstractLoginRequiredCommandHandlerTest {
32
33    def FILE = "/file.txt"
34
35    void testHandleCommand() {
36        assert fileSystem.createFile(FILE)
37        commandHandler.handleCommand(createCommand([FILE]), session)
38        assertSessionReply(ReplyCodes.RNFR_OK)
39        assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE
40    }
41
42    void testHandleCommand_PathIsRelative() {
43        assert fileSystem.createFile(FILE)
44        session.setAttribute(SessionKeys.CURRENT_DIRECTORY, "/")
45        commandHandler.handleCommand(createCommand(["file.txt"]), session)
46        assertSessionReply(ReplyCodes.RNFR_OK)
47        assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE
48    }
49
50    void testHandleCommand_PathDoesNotExistInFileSystem() {
51        commandHandler.handleCommand(createCommand([FILE]), session)
52        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE)
53        assert session.getAttribute(SessionKeys.RENAME_FROM) == null
54    }
55
56    void testHandleCommand_PathSpecifiesADirectory() {
57        assert fileSystem.createDirectory(FILE)
58        commandHandler.handleCommand(createCommand([FILE]), session)
59        assertSessionReply(ReplyCodes.EXISTING_FILE_ERROR, FILE)
60        assert session.getAttribute(SessionKeys.RENAME_FROM) == null
61    }
62
63    void testHandleCommand_MissingPathParameter() {
64        testHandleCommand_MissingRequiredParameter([])
65    }
66
67    //-------------------------------------------------------------------------
68    // Helper Methods
69    //-------------------------------------------------------------------------
70
71    CommandHandler createCommandHandler() {
72        new RnfrCommandHandler()
73    }
74
75    Command createValidCommand() {
76        return new Command(CommandNames.RNFR, [FILE])
77    }
78
79}