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.example;
17
18import org.mockftpserver.fake.FakeFtpServer;
19import org.mockftpserver.fake.UserAccount;
20import org.mockftpserver.fake.filesystem.DirectoryEntry;
21import org.mockftpserver.fake.filesystem.FileEntry;
22import org.mockftpserver.fake.filesystem.FileSystem;
23import org.mockftpserver.fake.filesystem.WindowsFakeFileSystem;
24import org.mockftpserver.test.AbstractTest;
25import org.mockftpserver.test.IntegrationTest;
26
27/**
28 * Example code illustrating how to programmatically configure a FakeFtpServer with a (simulated) Windows
29 * filesystem.
30 */
31public class SimpleWindowsFakeFtpServerTest extends AbstractTest 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 WindowsFakeFileSystem();
39        fileSystem.add(new DirectoryEntry("c:\\data"));
40        fileSystem.add(new FileEntry("c:\\data\\file1.txt", "abcdef 1234567890"));
41        fileSystem.add(new FileEntry("c:\\data\\run.exe"));
42        fakeFtpServer.setFileSystem(fileSystem);
43
44        fakeFtpServer.start();
45
46        fakeFtpServer.stop();
47    }
48
49}