使用Jayway的确定来验证XML属性(Verifying an XML attribute using Jayway's rest

编程入门 行业动态 更新时间:2024-10-13 14:28:51
使用Jayway的确定来验证XML属性(Verifying an XML attribute using Jayway's rest-assured)

我正在尝试使用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:getBankResponse

The @ 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>

更多推荐

本文发布于:2023-08-06 08:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1446891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   XML   Jayway   rest   attribute

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!