我想POST一个新对象并使用响应中的一个字段将我的URI映射到正确的resourceId。我在路径中使用@variable(' resourceId')@,但它使用文字URI字符串来发出请求,而不是使用POST响应中的resourceId填充。
有什么想法让这个有效吗?谢谢。
Given message itemPostRequestSingle
And <itemPostRequestSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostRequestSingle> header citrus_http_method is "POST"
-----> And <itemPostRequestSingle> header citrus_request_path is "/path/@variable('resourceId')@/path"
And <itemPostRequestSingle> payload is
"""
[
{
"relativeId": "${relativeId2}"
}
]
"""
Given message itemPostResponseSingle
And <itemPostResponseSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostResponseSingle> header citrus_http_status_code is "201"
And <itemPostResponseSingle> header citrus_http_reason_phrase is "CREATED"
And <itemPostResponseSingle> payload is
"""
[
{
"relativeId": "${relativeId}"
},
{
"relativeId": "${relativeId2}"
}
]
"""
Scenario: Example
Given variables
| relativeId | citrus:randomString(10,false) |
| relativeId2 | citrus:randomString(10,false) |
When <ApiClient> sends message <PostRequest>
And <ApiClient> should receive Json message <PostResponse>
And <ApiClient> sends message <itemPostRequestSingle>
Then <ApiClient> should receive Json message <itemPostResponseSingle>
答案 0 :(得分:0)
您正在混合验证匹配器表达式(例如@variable('resourceId')@
)和变量引用(例如${resourceId}
)。
您的itemPostRequestSingle
应该使用变量引用。您的PostResponse
应使用验证匹配器表达式,以便将id提取到变量resourceId
。
因此,我们的想法是使用验证匹配器表达式resourceId
提取@variable('resourceId')@
值,以便稍后在${resourceId}
的测试用例中引用该变量。