19d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/*
29d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Copyright 2007 the original author or authors.
39d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
49d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Licensed under the Apache License, Version 2.0 (the "License");
59d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * you may not use this file except in compliance with the License.
69d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * You may obtain a copy of the License at
79d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
89d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *      http://www.apache.org/licenses/LICENSE-2.0
99d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Unless required by applicable law or agreed to in writing, software
119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * distributed under the License is distributed on an "AS IS" BASIS,
129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * See the License for the specific language governing permissions and
149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * limitations under the License.
159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpackage org.mockftpserver.stub.example;
179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.command.CommandNames;
199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.stub.StubFtpServer;
209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.stub.command.PwdCommandHandler;
219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.AbstractTest;
229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.IntegrationTest;
239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/**
259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Example test using StubFtpServer, with programmatic configuration.
269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic class FtpWorkingDirectoryTest extends AbstractTest implements IntegrationTest {
289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final int PORT = 9981;
309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private FtpWorkingDirectory ftpWorkingDirectory;
319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private StubFtpServer stubFtpServer;
329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test FtpWorkingDirectory getWorkingDirectory() method
359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetWorkingDirectory() throws Exception {
379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        // Replace the existing (default) CommandHandler; customize returned directory pathname
399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        final String DIR = "some/dir";
409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        PwdCommandHandler pwdCommandHandler = new PwdCommandHandler();
419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        pwdCommandHandler.setDirectory(DIR);
429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubFtpServer.setCommandHandler(CommandNames.PWD, pwdCommandHandler);
439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubFtpServer.start();
459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        String workingDir = ftpWorkingDirectory.getWorkingDirectory();
479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("workingDirectory", DIR, workingDir);
499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @see org.mockftpserver.test.AbstractTest#setUp()
539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected void setUp() throws Exception {
559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        super.setUp();
569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        ftpWorkingDirectory = new FtpWorkingDirectory();
579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        ftpWorkingDirectory.setPort(PORT);
589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubFtpServer = new StubFtpServer();
599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubFtpServer.setServerControlPort(PORT);
609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @see org.mockftpserver.test.AbstractTest#tearDown()
649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected void tearDown() throws Exception {
669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        super.tearDown();
679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubFtpServer.stop();
689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair}
71