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 FtpWorkingDirectory ftpWorkingDirectory; 30 private StubFtpServer stubFtpServer; 31 32 /** 33 * Test FtpWorkingDirectory getWorkingDirectory() method 34 */ 35 public void testGetWorkingDirectory() throws Exception { 36 37 // Replace the existing (default) CommandHandler; customize returned directory pathname 38 final String DIR = "some/dir"; 39 PwdCommandHandler pwdCommandHandler = new PwdCommandHandler(); 40 pwdCommandHandler.setDirectory(DIR); 41 stubFtpServer.setCommandHandler(CommandNames.PWD, pwdCommandHandler); 42 43 stubFtpServer.start(); 44 45 String workingDir = ftpWorkingDirectory.getWorkingDirectory(); 46 47 assertEquals("workingDirectory", DIR, workingDir); 48 } 49 50 /** 51 * @see org.mockftpserver.test.AbstractTest#setUp() 52 */ 53 protected void setUp() throws Exception { 54 super.setUp(); 55 ftpWorkingDirectory = new FtpWorkingDirectory(); 56 stubFtpServer = new StubFtpServer(); 57 } 58 59 /** 60 * @see org.mockftpserver.test.AbstractTest#tearDown() 61 */ 62 protected void tearDown() throws Exception { 63 super.tearDown(); 64 stubFtpServer.stop(); 65 } 66 67} 68