跟进我可以在 Citrus 静态响应适配器有效负载中使用 Citrus 变量吗?
我正在使用 Citrus 2.7,我的测试扩展了 TestNGCitrusTestRunner:
@Test
@CitrusTest
public void testRequestOk() {
variable("myTest", "baz");
http(builder -> builder
.client("fooClient")
.send()
.post("/foo/bar")
.payload(new ClassPathResource("/foo/bar-baz.xml"))
.messageType(MessageType.XML)
.contentType("application/xml")
.accept("application/xml"));
http(builder -> builder
.client("fooClient")
.receive()
.response(HttpStatus.OK)
.validate("foo.bar", "baz"));
}
该请求被发送到 SUT,SUT 进而触发对 Citrus 的两个 http 调用(对 mockOne 和 mockTwo)。
使用以下配置:
<citrus-http:server id="mockOne"
port="9090"
auto-start="true"
endpoint-adapter="staticResponseAdapter"
security-handler="securityHandlerOne"/>
<citrus-http:server id="mockTwo"
port="9080"
auto-start="true"
endpoint-adapter="dispatchingEndpointAdapter"
security-handler="securityHandlerTwo"/>
...
<citrus:static-response-adapter id="staticResponseAdapter">
<citrus:payload>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar>${myTest}</bar>
</foo>
]]>
</citrus:payload>
</citrus:static-response-adapter>
我收到:com.consol.citrus.exceptions.CitrusRuntimeException: Unknown variable 'myTest'
在日志中,我看到最初设置了变量:
15:02:48,696 DEBUG citrus.Citrus| TEST STEP 1: create-variables
15:02:48,697 INFO reateVariablesAction| Setting variable: myTest to value: foo
15:02:48,697 DEBUG context.TestContext| Setting variable: myTest with value: 'foo'
但是在变量替换发生之前,Citrus 会这样做:
15:02:49,281 DEBUG ngHandlerInterceptor| Received Http request:
...
15:02:49,297 DEBUG t.TestContextFactory| Created new test context - using global variables: '{}'
15:02:49,299 DEBUG rusDispatcherServlet| Could not complete request
com.consol.citrus.exceptions.CitrusRuntimeException: Unknown variable 'myTest'
我做错了什么还是这是预期的行为?