我正在尝试使用Jayway的可靠保证的XML支持在以下XML中验证xmlns:ns1 =“http://thomas-bayer.com/blz/” 。
<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns1:getBankResponse xmlns:ns1="http://thomas-bayer.com/blz/"> <ns1:details> <ns1:bezeichnung>ABK-Kreditbank</ns1:bezeichnung> <ns1:bic>ABKBDEB1XXX</ns1:bic> <ns1:ort>Berlin</ns1:ort> <ns1:plz>10789</ns1:plz> </ns1:details> </ns1:getBankResponse> </soapenv:Body> </soapenv:Envelope>据我了解,
xmlns:ns1="http://thomas-bayer.com/blz/"是...的属性
<ns1:getBankResponse@前缀应返回与@后面的词干匹配的属性。
假设xmlString等于上面的SOAP响应XML,以下所有内容都返回null:
String nameSpace1 = given(xmlString).getString("Envelope.Body.getBankResponse.@xmlns:ns1"); String nameSpace2 = given(xmlString).getString("Envelope.Body.getBankResponse.@ns1"); String nameSpace3 = given(xmlString).getString("Envelope.Body.getBankResponse.@xmlns"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@xmlns:ns1"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@ns1"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@xmlns");任何帮助将不胜感激。
PS。 我知道,放心主要是关注RESTful API,但它可以用来测试SOAP。
I am trying to verify that xmlns:ns1="http://thomas-bayer.com/blz/" in the following XML using Jayway's rest-assured's XML support.
<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns1:getBankResponse xmlns:ns1="http://thomas-bayer.com/blz/"> <ns1:details> <ns1:bezeichnung>ABK-Kreditbank</ns1:bezeichnung> <ns1:bic>ABKBDEB1XXX</ns1:bic> <ns1:ort>Berlin</ns1:ort> <ns1:plz>10789</ns1:plz> </ns1:details> </ns1:getBankResponse> </soapenv:Body> </soapenv:Envelope>As I understand it,
xmlns:ns1="http://thomas-bayer.com/blz/"is an attribute of
<ns1:getBankResponseThe @ prefix should return an attribute matching the stem following the @.
Assume that xmlString is equal to the above SOAP response XML, all of the following have returned null:
String nameSpace1 = given(xmlString).getString("Envelope.Body.getBankResponse.@xmlns:ns1"); String nameSpace2 = given(xmlString).getString("Envelope.Body.getBankResponse.@ns1"); String nameSpace3 = given(xmlString).getString("Envelope.Body.getBankResponse.@xmlns"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@xmlns:ns1"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@ns1"); List<String> nameSpace = given(xmlString).get("Envelope.Body.getBankResponse[0].@xmlns");Any help would be greatly appreciated.
PS. I know that rest-assured is primarily concerned with RESTful APIs but it can be used to test SOAP.
最满意答案
在即将推出的REST Assured版本(可能是2.9.1)中,您将能够将XmlPath配置为不知道名称空间。 所以这意味着你可以这样做:
XmlPath xmlPath = new XmlPath(xmlResponse).using(xmlPathConfig().namespaceAware(false)); assertThat(xmlPath.getString("soapenv:Envelope.soapenv:Body.ns1:getBankResponse.@xmlns:ns1"), equalTo("http://thomas-bayer.com/blz/"));您可以在添加以下Maven存储库后依赖版本2.9.1-SNAPSHOT来尝试此操作:
<repositories> <repository> <id>sonatype</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> <snapshots /> </repository> </repositories>In the upcoming version of REST Assured (probably 2.9.1) you will be able to configure XmlPath to be unaware of namespaces. So this means you can do like this:
XmlPath xmlPath = new XmlPath(xmlResponse).using(xmlPathConfig().namespaceAware(false)); assertThat(xmlPath.getString("soapenv:Envelope.soapenv:Body.ns1:getBankResponse.@xmlns:ns1"), equalTo("http://thomas-bayer.com/blz/"));You can try this out today by depending on version 2.9.1-SNAPSHOT after having added the following Maven repository:
<repositories> <repository> <id>sonatype</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> <snapshots /> </repository> </repositories>更多推荐
发布评论