[size=medium][color=darkblue]
项目中使用ftp,由于在单元测试的时候不连接物理ftp,所以需要将ftp进行mock,当然了,在我们项目中只用了ftp的对单个文件进行,自己用socket来mock也不难,所以在网上找了一个,将用法记录在此,直接上代码。
[/color][/size]
[size=medium][color=darkblue]
代码非常好理解,然后这个只用了最简单的功能,以后有时间了,再研究一下。
[/color][/size]
项目中使用ftp,由于在单元测试的时候不连接物理ftp,所以需要将ftp进行mock,当然了,在我们项目中只用了ftp的对单个文件进行,自己用socket来mock也不难,所以在网上找了一个,将用法记录在此,直接上代码。
[/color][/size]
FakeFtpServer fakeFtpServer = new FakeFtpServer();
fakeFtpServer.setServerControlPort(7777);
// 创建服务器 添加用户
fakeFtpServer.addUserAccount(new UserAccount("123", "123", "/"));
// 建立文件系统
FileSystem fileSystem = new UnixFakeFileSystem();
fileSystem.add(new DirectoryEntry("/"));
fileSystem.add(new FileEntry("/aaa", FileUtils.getContentFromClassPath("/ftp/aaa")));
fileSystem.add(new FileEntry("/aaa.md5", FileUtils.getContentFromClassPath("/ftp/aaa.md5")));
fileSystem.add(new FileEntry("/bbb.txt", FileUtils
.getContentFromClassPath("/ftp/bbb.txt")));
fileSystem.add(new FileEntry("/bbb.txt.md5", FileUtils
.getContentFromClassPath("/ftp/bbb.txt.md5")));
fakeFtpServer.setFileSystem(fileSystem);
fakeFtpServer.start();
[size=medium][color=darkblue]
代码非常好理解,然后这个只用了最简单的功能,以后有时间了,再研究一下。
[/color][/size]