1

我正在使用 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 有关吗?

4

1 回答 1

0

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

于 2016-11-17T14:31:39.413 回答