上Can I use Citrus variable in Citrus static response adapter payload?如何訪問變量中(柑橘)的靜態響應適配器
跟進我使用柑橘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 ,這反過來又觸發了兩個對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'
在日誌中,我看到intially的變量設置:
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'
但右邊的變量替換之前應該發生,柑橘這樣做:
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'
我做錯了什麼或者這是預期的行爲?
感謝您的回覆和建議的解決方案。它在給我的http服務器組件添加超時後完美運行。 –