0

我正在尝试接收上传到(柑橘)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());
    }
}
4

1 回答 1

1

我已经设法测试文件内容,添加一个ChannelEndpoint从 ftp 工作目录读取文件的文件。然后我可以这样做测试文件内容:

receive(fileEndpoint)
            .header("file_originalFile", "@contains('/test.txt')@")
            .payload(new ClassPathResource("ar/com/jidev/citrus/samples/expected/test.txt"));

有关更多信息,我在此处上传了完整示例

于 2017-11-01T21:34:26.527 回答