1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.ftp;
18
19 import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import junit.framework.Test;
25
26 import org.apache.commons.io.FileUtils;
27 import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
28 import org.apache.ftpserver.ftplet.FileSystemFactory;
29 import org.apache.ftpserver.ftplet.FileSystemView;
30 import org.apache.ftpserver.ftplet.FtpException;
31 import org.apache.ftpserver.ftplet.User;
32
33
34
35
36 public class FtpProviderUserDirTestCase extends FtpProviderTestCase {
37
38
39
40
41 public static Test suite() throws Exception {
42 return suite(new FtpProviderUserDirTestCase());
43 }
44
45
46
47
48 @Override
49 protected FileSystemFactory getFtpFileSystem() throws IOException {
50
51 final File testDir = new File(getTestDirectory());
52 final File rootDir = new File(testDir, "homeDirIsRoot");
53 final File homesDir = new File(rootDir, "home");
54 final File initialDir = new File(homesDir, "test");
55 FileUtils.deleteDirectory(rootDir);
56
57 rootDir.mkdir();
58 FileUtils.copyDirectory(testDir, initialDir, pathName -> !pathName.getPath().contains(rootDir.getName()));
59
60 return new NativeFileSystemFactory() {
61 @Override
62 public FileSystemView createFileSystemView(final User user) throws FtpException {
63 final FileSystemView fsView = super.createFileSystemView(user);
64 fsView.changeWorkingDirectory("home/test");
65 return fsView;
66 }
67 };
68 }
69
70
71
72
73 @Override
74 protected String getFtpRootDir() {
75 return new File(getTestDirectory(), "homeDirIsRoot").getPath();
76 }
77
78
79
80
81 @Override
82 protected boolean getUserDirIsRoot() {
83 return true;
84 }
85
86 }