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