1/*
2 * Copyright 2007 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.stub.example;
17
18import org.mockftpserver.core.command.CommandNames;
19import org.mockftpserver.stub.StubFtpServer;
20import org.mockftpserver.stub.command.PwdCommandHandler;
21import org.mockftpserver.test.AbstractTest;
22import org.mockftpserver.test.IntegrationTest;
23
24/**
25 * Example test using StubFtpServer, with programmatic configuration.
26 */
27public class FtpWorkingDirectoryTest extends AbstractTest implements IntegrationTest {
28
29    private static final int PORT = 9981;
30    private FtpWorkingDirectory ftpWorkingDirectory;
31    private StubFtpServer stubFtpServer;
32
33    /**
34     * Test FtpWorkingDirectory getWorkingDirectory() method
35     */
36    public void testGetWorkingDirectory() throws Exception {
37
38        // Replace the existing (default) CommandHandler; customize returned directory pathname
39        final String DIR = "some/dir";
40        PwdCommandHandler pwdCommandHandler = new PwdCommandHandler();
41        pwdCommandHandler.setDirectory(DIR);
42        stubFtpServer.setCommandHandler(CommandNames.PWD, pwdCommandHandler);
43
44        stubFtpServer.start();
45
46        String workingDir = ftpWorkingDirectory.getWorkingDirectory();
47
48        assertEquals("workingDirectory", DIR, workingDir);
49    }
50
51    /**
52     * @see org.mockftpserver.test.AbstractTest#setUp()
53     */
54    protected void setUp() throws Exception {
55        super.setUp();
56        ftpWorkingDirectory = new FtpWorkingDirectory();
57        ftpWorkingDirectory.setPort(PORT);
58        stubFtpServer = new StubFtpServer();
59        stubFtpServer.setServerControlPort(PORT);
60    }
61
62    /**
63     * @see org.mockftpserver.test.AbstractTest#tearDown()
64     */
65    protected void tearDown() throws Exception {
66        super.tearDown();
67        stubFtpServer.stop();
68    }
69
70}
71