Home | History | Annotate | Download | only in example
      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  */
     16 package org.mockftpserver.fake.example;
     17 
     18 import org.mockftpserver.fake.FakeFtpServer;
     19 import org.mockftpserver.fake.UserAccount;
     20 import org.mockftpserver.fake.filesystem.DirectoryEntry;
     21 import org.mockftpserver.fake.filesystem.FileEntry;
     22 import org.mockftpserver.fake.filesystem.FileSystem;
     23 import org.mockftpserver.fake.filesystem.UnixFakeFileSystem;
     24 import org.mockftpserver.test.AbstractTestCase;
     25 import org.mockftpserver.test.IntegrationTest;
     26 
     27 /**
     28  * Example code illustrating how to programmatically configure a FakeFtpServer with a (simulated) Unix
     29  * filesystem.
     30  */
     31 public class SimpleUnixFakeFtpServerTest extends AbstractTestCase implements IntegrationTest {
     32 
     33     public void testConfigureAndStart() throws Exception {
     34         FakeFtpServer fakeFtpServer = new FakeFtpServer();
     35         fakeFtpServer.setServerControlPort(9981);
     36         fakeFtpServer.addUserAccount(new UserAccount("user", "password", "c:\\data"));
     37 
     38         FileSystem fileSystem = new UnixFakeFileSystem();
     39         fileSystem.add(new DirectoryEntry("/data"));
     40         fileSystem.add(new FileEntry("/data/file1.txt", "abcdef 1234567890"));
     41         fileSystem.add(new FileEntry("/data/run.exe"));
     42         fakeFtpServer.setFileSystem(fileSystem);
     43 
     44         fakeFtpServer.start();
     45 
     46         fakeFtpServer.stop();
     47     }
     48 
     49 }