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