我可以在 Citrus 静态响应适配器负载中使用 Citrus 变量吗?
Can I use Citrus variable in Citrus static response adapter payload?
我正在使用静态响应端点适配器来return从资源文件获取的模拟服务响应:
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 Endpoint Responses 变量的内置机制?
一般的静态响应适配器和端点适配器目前不支持测试变量。
Edit:从 Citrus 2.6.2 开始,您可以在静态响应适配器中使用测试变量。请参阅此处的文档:http://www.citrusframework.org/reference/html/endpoint-adapter.html#static-response-endpoint-adapter
我正在使用静态响应端点适配器来return从资源文件获取的模拟服务响应:
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 Endpoint Responses 变量的内置机制?
一般的静态响应适配器和端点适配器目前不支持测试变量。
Edit:从 Citrus 2.6.2 开始,您可以在静态响应适配器中使用测试变量。请参阅此处的文档:http://www.citrusframework.org/reference/html/endpoint-adapter.html#static-response-endpoint-adapter