We use the REST-assured framework for doing some unit/integration testing in Java.
The XML answer from a REST service is similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<Items xmlns="urn:service:com:namespace:item/1"
returned="3" found="3">
<ItemRef object="urn:svc:com:car:item:123456" type="door">door-123456.pdf</ItemRef>
<ItemRef object="urn:svc:com:car:item:983425" type="mirror">mirror-43562577.pdf</ItemRef>
<ItemRef object="urn:svc:com:car:item:983425" type="wheel" >door-94584854.pdf</ItemRef>
</Items>
In my test I am interested to check the number of items returned by reading the attribute returned
like this
givenOK()
.expect()
.body("Items.@returned", equalTo("3")) // this is a string
.when()
.get(myurl)
And it works well
Now I want as well to control if the URN in the xmlns is correct with the same logic:
givenOK()
.expect()
.body("Items.@returned", equalTo("3")) // this is a string
.body("Items.@xmlns", equalTo("urn:service:com:namespace:item/1"))
.when()
.get(myurl)
But when my test run, the expression Items.@xmlns
seems not returning the value of the attribute but empty: []
Any idea why this is not working?
Could it be that the "xmlns" attribute is treated specially because it indicates a namespace?
A possible work-around would be to declare the namespace in the XmlConfig and verify something in the body.
And another example with multiple nodes and attributes (explicit path):