是否可以为Citrus静态响应适配器响应模板应用字典?

时间:2016-11-16 10:00:42

标签: citrus-framework

我使用Citrus静态响应适配器来模拟服务,我需要为每个测试用例更改其有效负载中的值。理想情况下,我考虑使用每个测试用例的字典。有我当前场景的样本:

@Autowired
@Qualifier("checkRegistrationEndpointAdapter")
public StaticResponseEndpointAdapter checkRegistrationEndpointAdapter;

protected void setAdapterResponse(StaticResponseEndpointAdapter adapter, String filenamepath){
    URL url = this.getClass().getResource(filenamepath);
    String payload = null;
    try {
        payload = Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        e.printStackTrace();
    }
    adapter.setMessagePayload(payload);
}
@CitrusTest
public void TestCase02() throws IOException {

    http()
            .client(CLIENT)
            .post()
            .payload(new ClassPathResource("templates/thisStartRequestMsg.xml", getClass()))
            .dictionary("TC02");

    http()
            .client(CLIENT)
            .response()
            .messageType("xml")
            .payload(new ClassPathResource("templates/thisStartResponseMsg.xml", getClass()));

    action(new AbstractTestAction() {
        @Override
        public void doExecute(TestContext testContext) {
            setAdapterResponse(checkRegistrationEndpointAdapter, "templates/check-registration-v1CheckRegistrationResponseMsg.xml");
        }
    });

    http()
            .client(CLIENT)
            .response()
            .messageType("xml")
            .payload(new ClassPathResource("templates/check-registration-v1CheckRegistrationRequestMsg.xml", getClass()))
            .dictionary("TC02");
}

如何将字典应用于 setAdapterResponse 方法中设置的有效负载? 注意:此问题与Can I use Citrus variable in Citrus static response adapter payload?

有关

1 个答案:

答案 0 :(得分:0)

静态响应适配器目前不支持数据字典。我想知道你为什么要在静态响应适配器上投入这么多精力?为什么不使用完整的Citrus http服务器电源来接收请求并在测试用例中提供响应?