我正在使用静态响应端点适配器返回从资源文件中获取的模拟服务响应:
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));
}
文件 templates/helloResponses/ReqIdGenerator.xml 内容是:
<xml>
<id>${randomRequestIdentifier}</id>
</xml>
我认为应该用它的当前值替换该变量。我错了吗?是否有内置机制来支持 Citrus 端点响应中的变量?