0

I'm trying to use the citrus-framework to test an integration that writes some files on a FTP server.

I need to wait until some file is uploaded to the ftp (I'm using waitFor().condition() statement to accomplish that) and then receive the messages sent and do some assertions.

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);
    }
}

When I try to run this test looks like the waitFor() is never executed and ftpServer.createConsumer().receive(context); is executed before any file could be uploaded to the FTP.

This is the error that I'm getting:

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

Any idea how I could fix this? Also any complete example for using FTP Java DSL with Citrus would be more than welcome!

4

1 回答 1

1

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

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

只有这样,测试设计者才能按正确的顺序安排测试动作。这是因为测试设计者首先构建了完整的测试动作逻辑,并且执行发生在测试方法的最后。

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

于 2017-10-25T07:44:24.353 回答