本文介绍了我可以在Citrus静态响应适配器有效负载中使用Citrus变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用静态响应端点适配器返回从资源文件获取的模拟服务响应:

  private void setAdapterResponse staticResponseEndpointAdapter adapter,String response)throws IOException {

URL url = Resources.getResource(response);
adapter.setMessagePayload(Resources.toString(url,Charsets.UTF_8));
}

@Autowired
private Endpoint helloSoapClient;

@Autowired
private WebServiceServer helloMockService;

@Autowired
private StaticResponseEndpointAdapter helloResponseAdapter;

@CitrusTest(name =HELLO_WORLD)
public void sendAndReceiveMessage()throws IOException {

variable(randomRequestIdentifier,9978111203033);
variable(constantDate,201301010000);

setAdapterResponse(helloResponseAdapter,templates / helloResponses / ReqIdGenerator.xml);

send(helloSoapClient)
.payload(new ClassPathResource(templates / helloRequests / HelloRequest028.xml));
receive(helloSoapClient)
.payload(new ClassPathResource(templates / helloResponses / HelloResponse028.xml));
}



private void setAdapterResponse(StaticResponseEndpointAdapter adapter,String response)throws IOException {

URL url = Resources.getResource );
adapter.setMessagePayload(Resources.toString(url,Charsets.UTF_8));
}

文件模板/ helloResponses / ReqIdGenerator.xml的内容是:

 < xml> 
< id> $ {randomRequestIdentifier}< / id>
< / xml>

我认为变量应该被替换为当前值。我错了吗?是否有内置机制来支持Citrus端点响应中的变量?

解决方案

静态响应适配器和端点适配器通常

:从柑橘2.6.2开始,您可以使用测试变量静态响应适配器。请参阅这里的文档:


I am using static response endpoint adapter to return a mock service response taken from a resource file:

            private void setAdapterResponse(StaticResponseEndpointAdapter adapter, String response) throws IOException{

                            URL url = Resources.getResource(response);
                            adapter.setMessagePayload(Resources.toString(url, Charsets.UTF_8));
            }

            @Autowired
            private Endpoint helloSoapClient;

            @Autowired
            private WebServiceServer helloMockService;

            @Autowired
            private StaticResponseEndpointAdapter helloResponseAdapter;

            @CitrusTest(name = "HELLO_WORLD")
            public void sendAndReceiveMessage() throws IOException{

                            variable("randomRequestIdentifier", "9978111203033");
                            variable("constantDate", "201301010000");

                            setAdapterResponse(helloResponseAdapter, "templates/helloResponses/ReqIdGenerator.xml");

                            send(helloSoapClient)
                            .payload(new ClassPathResource("templates/helloRequests/HelloRequest028.xml"));
                            receive(helloSoapClient)
                            .payload(new ClassPathResource("templates/helloResponses/HelloResponse028.xml"));
            }



            private void setAdapterResponse(StaticResponseEndpointAdapter adapter, String response) throws IOException{

            URL url = Resources.getResource(response);
            adapter.setMessagePayload(Resources.toString(url, Charsets.UTF_8));
            }

the file templates/helloResponses/ReqIdGenerator.xml contents is:

<xml>
  <id>${randomRequestIdentifier}</id>
</xml>

I thought that variable should be replaced with its current value. Am I wrong? Is there a build-in mechanism to support variables in Citrus Endpoint Responses?

解决方案

The static response adapter and endpoint adapters in general do not support test variables at the moment.

Edit: Since Citrus 2.6.2 you can use test variables in static response adapter. See documentation here: http://www.citrusframework.org/reference/html/endpoint-adapter.html#static-response-endpoint-adapter

这篇关于我可以在Citrus静态响应适配器有效负载中使用Citrus变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 21:48