柑橘 waitFor().condition() 语句在与 ftpServer 一起使用时不等待

citrus waitFor().condition() statement not waiting when used with ftpServer

我正在尝试使用柑橘框架来测试在 FTP 服务器上写入一些文件的集成。

我需要等到某些文件上传到 ftp(我正在使用 waitFor().condition() 语句来完成)然后接收发送的消息并做一些断言。

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.condition.Condition;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
import com.consol.citrus.ftp.server.FtpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.testng.annotations.Test;

import java.io.File;

@ActiveProfiles(value = "ftpTest")
@Test
public class FtpTest extends TestNGCitrusTestDesigner {
    @Autowired
    FtpServer ftpServer;
    @Autowired
    TestContext context;

    @CitrusTest(name = "ftpTest")
    public void ftpTest() {

        // here I start my integration that uses a cron to upload the file
        // this code is irrelevant for the example

        Condition waitUntilFileIsUploaded = new Condition() {
            @Override
            public String getName () {
                return "Check files on FTP";
            }

            @Override
            public boolean isSatisfied (TestContext testContext){
                return new File("/tmp/foo_dir").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(120L).interval(500L);
        ftpServer.createConsumer().receive(context);
    }
}

当我尝试 运行 时,这个测试看起来 waitFor() 从未执行,ftpServer.createConsumer().receive(context); 在任何文件可以上传到 FTP 之前执行。

这是我遇到的错误:

ftpTest>TestNGCitrusTest.run:57->TestNGCitrusTest.run:111->TestNGCitrusTestDesigner.invokeTestMethod:73->TestNGCitrusTest.invokeTestMethod:133->ftpTest:49 » ActionTimeout

知道如何解决这个问题吗? 此外,任何使用 FTP Java DSL with Citrus 的完整示例都非常受欢迎!

请使用测试设计器接收方法,而不是自行创建消费者。

receive(ftpServer)
       .header("some-header", "some-value")
       .payload("some payload");

只有这样,测试设计人员才能将测试动作安排得井井有条。这是因为测试设计人员首先构建完整的测试操作逻辑,并且在测试方法的最后执行。

作为替代方案,您也可以使用测试运行器而不是测试设计器。运行程序将立即执行每个测试操作,让您有机会像以前一样添加自定义语句。