blob: 1f311718e44d71563797ee69a08ad1b0173187af [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
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
23import org.mockftpserver.fake.filesystem.Permissions
24
25/**
26 * Tests for RnfrCommandHandler
27 *
28 * @version $Revision$ - $Date$
29 *
30 * @author Chris Mair
31 */
32class RnfrCommandHandlerTest extends AbstractFakeCommandHandlerTestCase {
33
34 private static final FILE = "/file.txt"
35 private static final DIR = "/subdir"
36
37 void testHandleCommand() {
38 createFile(FILE)
39 handleCommand([FILE])
40 assertSessionReply(ReplyCodes.RNFR_OK, 'rnfr')
41 assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE
42 }
43
44 void testHandleCommand_PathIsRelative() {
45 createFile(FILE)
46 session.setAttribute(SessionKeys.CURRENT_DIRECTORY, "/")
47 handleCommand(["file.txt"])
48 assertSessionReply(ReplyCodes.RNFR_OK, 'rnfr')
49 assert session.getAttribute(SessionKeys.RENAME_FROM) == FILE
50 }
51
52 void testHandleCommand_PathDoesNotExistInFileSystem() {
53 handleCommand([FILE])
54 assertSessionReply(ReplyCodes.READ_FILE_ERROR, ['filesystem.doesNotExist', FILE])
55 assert session.getAttribute(SessionKeys.RENAME_FROM) == null
56 }
57
58 void testHandleCommand_PathSpecifiesADirectory() {
59 createDirectory(DIR)
60 handleCommand([DIR])
61 assertSessionReply(ReplyCodes.RNFR_OK, 'rnfr')
62 assert session.getAttribute(SessionKeys.RENAME_FROM) == DIR
63 }
64
65 void testHandleCommand_NoReadAccessToFile() {
66 createFile(FILE)
67 fileSystem.getEntry(FILE).permissions = new Permissions('-wx-wx-wx')
68 handleCommand([FILE])
69 assertSessionReply(ReplyCodes.READ_FILE_ERROR, ['filesystem.cannotRead', FILE])
70 }
71
72 void testHandleCommand_MissingPathParameter() {
73 testHandleCommand_MissingRequiredParameter([])
74 }
75
76 //-------------------------------------------------------------------------
77 // Helper Methods
78 //-------------------------------------------------------------------------
79
80 CommandHandler createCommandHandler() {
81 new RnfrCommandHandler()
82 }
83
84 Command createValidCommand() {
85 return new Command(CommandNames.RNFR, [FILE])
86 }
87
88}