177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/*
277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Copyright 2008 the original author or authors.
377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair *
477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Licensed under the Apache License, Version 2.0 (the "License");
577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * you may not use this file except in compliance with the License.
677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * You may obtain a copy of the License at
777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair *
877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair *      http://www.apache.org/licenses/LICENSE-2.0
977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair *
1077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Unless required by applicable law or agreed to in writing, software
1177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * distributed under the License is distributed on an "AS IS" BASIS,
1277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * See the License for the specific language governing permissions and
1477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * limitations under the License.
1577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */
1677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpackage org.mockftpserver.fake.example;
1777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
1877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.FakeFtpServer;
1977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.UserAccount;
2077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.filesystem.DirectoryEntry;
2177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.filesystem.FileEntry;
2277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.filesystem.FileSystem;
2377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.fake.filesystem.UnixFakeFileSystem;
2477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.test.AbstractTest;
2577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairimport org.mockftpserver.test.IntegrationTest;
2677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
2777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair/**
2877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * Example code illustrating how to programmatically configure a FakeFtpServer with a (simulated) Unix
2977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair * filesystem.
3077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair */
3177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismairpublic class SimpleUnixFakeFtpServerTest extends AbstractTest implements IntegrationTest {
3277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
3377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair    public void testConfigureAndStart() throws Exception {
3477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        FakeFtpServer fakeFtpServer = new FakeFtpServer();
3577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fakeFtpServer.setServerControlPort(9981);
3677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fakeFtpServer.addUserAccount(new UserAccount("user", "password", "c:\\data"));
3777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
3877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        FileSystem fileSystem = new UnixFakeFileSystem();
3977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fileSystem.add(new DirectoryEntry("/data"));
4077b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fileSystem.add(new FileEntry("/data/file1.txt", "abcdef 1234567890"));
4177b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fileSystem.add(new FileEntry("/data/run.exe"));
4277b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fakeFtpServer.setFileSystem(fileSystem);
4377b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
4477b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fakeFtpServer.start();
4577b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
4677b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair        fakeFtpServer.stop();
4777b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair    }
4877b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair
4977b8661f08d1379c0bdf2af93d8004fced9f1ab0chrismair}