我正在尝试接收上传到(柑橘)ftp 服务器的文件,并验证上传文件的内容是否符合预期。
我已经成功接收到STOR
消息(下面是我的代码),但我不知道如何测试内容是否等于某些文本(我正在使用 xml、json 和 csv 文件)。
你能帮助我吗?谢谢。
@Test
public class SampleFtpTest extends TestNGCitrusTestDesigner {
@Autowired
private FtpServer ftpServer;
@CitrusTest
public void testFileContent() {
Condition waitUntilFileIsUploaded = new Condition() {
@Override
public String getName () {
return "Check files on FTP";
}
@Override
public boolean isSatisfied (TestContext testContext){
return new File("target/ftp/user/anonymous").listFiles().length != 0;
}
@Override
public String getSuccessMessage (TestContext testContext){
return "Files found in FTP!";
}
@Override
public String getErrorMessage (TestContext testContext){
return "No file was found in FTP";
}
};
waitFor().condition(waitUntilFileIsUploaded).seconds(1200L).interval(5000L);
// simulate integration uploading a file...
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(20000L);
Runtime.getRuntime().exec("curl -T /tmp/test.txt ftp://localhost:22222 --user anonymous:secret");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
// don't care about connection related messages
receive(ftpServer);
receive(ftpServer);
receive(ftpServer);
receive(ftpServer);
receive(ftpServer);
// i'd like to assert that the uploaded files content is as expected
receive(ftpServer).header("citrus_ftp_command", FTPCmd.STOR.getCommand());
}
}