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.apache.log4j.Logger; 19import org.mockftpserver.fake.FakeFtpServer; 20import org.mockftpserver.fake.filesystem.DirectoryEntry; 21import org.mockftpserver.fake.filesystem.FileEntry; 22import org.mockftpserver.fake.filesystem.FileSystem; 23import org.mockftpserver.fake.filesystem.Permissions; 24import org.mockftpserver.fake.filesystem.WindowsFakeFileSystem; 25import org.mockftpserver.test.AbstractTest; 26import org.mockftpserver.test.IntegrationTest; 27 28/** 29 * Example code illustrating how to programmatically configure a FakeFtpServer with a (simulated) Windows 30 * filesystem, and including file/directory permissions. 31 */ 32public class WindowsFakeFileSystemPermissionsTest extends AbstractTest implements IntegrationTest { 33 34 private static final Logger LOG = Logger.getLogger(WindowsFakeFileSystemPermissionsTest.class); 35 36 public void testFilesystemWithPermissions() throws Exception { 37 38 final String USER1 = "joe"; 39 final String USER2 = "mary"; 40 final String GROUP = "dev"; 41 final String CONTENTS = "abcdef 1234567890"; 42 43 FileSystem fileSystem = new WindowsFakeFileSystem(); 44 DirectoryEntry directoryEntry1 = new DirectoryEntry("c:\\"); 45 directoryEntry1.setPermissions(new Permissions("rwxrwx---")); 46 directoryEntry1.setOwner(USER1); 47 directoryEntry1.setGroup(GROUP); 48 49 DirectoryEntry directoryEntry2 = new DirectoryEntry("c:\\data"); 50 directoryEntry2.setPermissions(Permissions.ALL); 51 directoryEntry2.setOwner(USER1); 52 directoryEntry2.setGroup(GROUP); 53 54 FileEntry fileEntry1 = new FileEntry("c:\\data\\file1.txt", CONTENTS); 55 fileEntry1.setPermissionsFromString("rw-rw-rw-"); 56 fileEntry1.setOwner(USER1); 57 fileEntry1.setGroup(GROUP); 58 59 FileEntry fileEntry2 = new FileEntry("c:\\data\\run.exe"); 60 fileEntry2.setPermissionsFromString("rwxrwx---"); 61 fileEntry2.setOwner(USER2); 62 fileEntry2.setGroup(GROUP); 63 64 fileSystem.add(directoryEntry1); 65 fileSystem.add(directoryEntry2); 66 fileSystem.add(fileEntry1); 67 fileSystem.add(fileEntry2); 68 69 FakeFtpServer fakeFtpServer = new FakeFtpServer(); 70 fakeFtpServer.setFileSystem(fileSystem); 71 72 LOG.info(fileSystem); 73 } 74 75}