Can I use Citrus variable in Citrus static response adapter payload?

爱⌒轻易说出口 提交于 2019-12-02 14:44:59

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/40388363/can-i-use-citrus-variable-in-citrus-static-response-adapter-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!