mockftpserverを使用してftpテストを行います
詳細
プロジェクトではftpを使用し、ユニットテスト時に物理ftpに接続しないため、ftpをmockする必要があります.もちろん、私たちのプロジェクトではftpだけを使って単一のファイルを行い、自分でsocketでmockをするのも難しくないので、ネット上で1つ探して、使い方をここに記録して、直接コードをつけました.
コードはとてもよく理解して、それからこれは最も簡単な機能だけを使って、後で時間があって、更に研究します.
プロジェクトではftpを使用し、ユニットテスト時に物理ftpに接続しないため、ftpをmockする必要があります.もちろん、私たちのプロジェクトではftpだけを使って単一のファイルを行い、自分でsocketでmockをするのも難しくないので、ネット上で1つ探して、使い方をここに記録して、直接コードをつけました.
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();
コードはとてもよく理解して、それからこれは最も簡単な機能だけを使って、後で時間があって、更に研究します.