AppeCommandHandlerTest.groovy revision d150a70ca8f8ad6cc300cf56174c8846066a4ad4
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.fake.filesystem.FileEntry
23
24
25/**
26 * Tests for AppeCommandHandler
27 *
28 * @version $Revision$ - $Date$
29 *
30 * @author Chris Mair
31 */
32class AppeCommandHandlerTest extends AbstractStoreFileCommandHandlerTest {
33
34    void testHandleCommand_MissingPathParameter() {
35        testHandleCommand_MissingRequiredParameter([])
36    }
37
38    void testHandleCommand_AbsolutePath() {
39        testHandleCommand([FILE], 'appe', CONTENTS)
40    }
41
42    void testHandleCommand_AbsolutePath_FileAlreadyExists() {
43        def ORIGINAL_CONTENTS = '123 456 789'
44        fileSystem.addEntry(new FileEntry(path: FILE, contents: ORIGINAL_CONTENTS))
45        testHandleCommand([FILE], 'appe', ORIGINAL_CONTENTS + CONTENTS)
46    }
47
48    void testHandleCommand_RelativePath() {
49        setCurrentDirectory(DIR)
50        testHandleCommand([FILENAME], 'appe', CONTENTS)
51    }
52
53    void testHandleCommand_PathSpecifiesAnExistingDirectory() {
54        createDirectory(FILE)
55        commandHandler.handleCommand(createCommand([FILE]), session)
56        assertSessionReply(ReplyCodes.FILENAME_NOT_VALID, FILE)
57    }
58
59    void testHandleCommand_ParentDirectoryDoesNotExist() {
60        def NO_SUCH_DIR = "/path/DoesNotExist"
61        handleCommand([p(NO_SUCH_DIR, FILENAME)])
62        assertSessionReply(ReplyCodes.FILENAME_NOT_VALID, NO_SUCH_DIR)
63    }
64
65    //-------------------------------------------------------------------------
66    // Helper Methods
67    //-------------------------------------------------------------------------
68
69    CommandHandler createCommandHandler() {
70        new AppeCommandHandler()
71    }
72
73    Command createValidCommand() {
74        return new Command(CommandNames.APPE, [FILE])
75    }
76
77    void setUp() {
78        super.setUp()
79    }
80
81    protected String verifyOutputFile() {
82        assert fileSystem.isFile(FILE)
83        assert session.getReplyMessage(1).contains(FILENAME)
84        return FILE
85    }
86
87}