我有以下 SOAP 响应消息,如果项目导入成功,我需要验证响应代码是否为 1。如何使用 RestAssured 和 Java 做到这一点?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<env:Envelope
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header/>
<env:Body>
<n1:importProjectResponse
xmlns:n1=" some text here......"
xmlns:n2="..some text here...."
xsi:type="n2:ArrayOfProjectImportResultCode">
<n2:ProjectImportResultCode>
<n2:code>1</n2:code>
<n2:message>Project 'test1' import was successful.</n2:message>
</n2:ProjectImportResultCode>
</n1:importProjectResponse>
</env:Body></env:Envelope>
我正在使用 RestAssured 进行测试,如果我可以通过利用 RestAssured 而不是编写更多类或方法来完成看似简单的任务来避免代码膨胀,那就太好了。有任何想法吗?
到目前为止我尝试过,这当然不起作用..
response = given().
auth().basic(USER, PASSWORD).
body(request).
headers("Content-type", "text/xml").
expect().
statusCode(200).
body("//n2:code/text()", is("1")). // does not match .. hmmm :(
when().post(URL);