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