sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

XML Body is parsed with namespace unaware parser, XPathMatchers fail #171

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Have A Server return xml with namespaces in the body. eg:
<ns:root xmlns:ns=\"http://doo.bar.com\">Foo</ns:root>

2. Test:

given().
    header("Accept", "application/xml").
      expect().body(not(hasXPath("/root"))).
    when().
            get("/resourceName");

Expected Output: The Test should succed. What really Happens: Test fails.

Proposed Fix:
In BodyMatcher make the DocumentBuilderFactory namespace aware. Instead of:
Element node = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new 
ByteArrayInputStream(response.asByteArray())).getDocumentElement();

Have
factory = DocumentBuilderFactory.newInstance()
factory.setNamespaceAware(true);
Element node = factory.newDocumentBuilder().parse(new 
ByteArrayInputStream(response.asByteArray())).getDocumentElement();

Original issue reported on code.google.com by martinEi...@gmail.com on 16 May 2012 at 7:09

GoogleCodeExporter commented 9 years ago
Hi, 

Could you please help out by creating a patch or pull request with the fix 
including a test case that validates it? That would be awesome!

Regards,
/Johan

Original comment by johan.ha...@gmail.com on 16 May 2012 at 7:55

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 21 Nov 2013 at 1:31