How do I access a citrus http receive message body in Java?(如何在 Java 中访问 citrus http 接收消息正文?)
问题描述
我同时使用黄瓜和柑橘,在我的 @Then
定义中,我有柑橘 HTTP 响应:
I'm using cucumber and citrus together, and in my @Then
definition, I have the citrus HTTP response:
@CitrusResource TestRunner runner;
runner.http(builder -> {
final HttpClientResponseActionBuilder rab =
builder.client("citrusEndpointAPI").receive()
.response(HttpStatus.OK).messageType(MessageType.JSON)
.contentType(MediaType.APPLICATION_JSON_VALUE);
有没有办法将返回的 JSON 消息体存储到 java JSON 对象中?
Is there a way to store the returned JSON message body into a java JSON object?
推荐答案
您可以使用本地消息存储.在测试期间,每条消息都应保存到本地的内存存储中.您可以稍后在该测试用例中通过其名称访问存储的消息:
You can use the local message store. Each message should be saved to that local in memory storage during the test. You can access the stored messages later in that test case via its name:
receive(action -> action.endpoint("sampleEndpoint")
.name("sampleMessage")
.payload("..."));
echo("citrus:message(sampleMessage.payload())");
请注意,我们将收到的消息命名为 sampleMessage
.您也可以通过自定义测试操作中的测试上下文访问消息存储.
Please note that we named the received message sampleMessage
. You can access the message store via test context in custom test actions, too.
context.getMessageStore().getMessage("sampleMessage");
此外,您还可以在 Java DSL 中使用自定义消息验证回调.在这里,您可以完全访问收到的消息内容.
Besides that you could also use a custom message validation callback in Java DSL. Here you have full access to the received message content.
receive(action -> action.endpoint("sampleEndpoint")
.validationCallback((message, context) -> {
//Do something with message content
message.getPayload(String.class);
}));
这篇关于如何在 Java 中访问 citrus http 接收消息正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中访问 citrus http 接收消息正文?


- 获取数字的最后一位 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01