djangid / rest-assured

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

Chaining of .body() calls results in false positives with hamcrest's hasXPath() and not() #215

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Have your restful server returning xml, how about at /xml

This works:
 given().spec(getRequest).expect()
        .body(hasXPath("//someNode[@attr='yes']"))
        .body(hasXPath("//someOther[@attr='no']"))
    .when().get("/xml");

This does not work, because the not-wrapped call will pass even if it shouldn't:
 given().spec(getRequest).expect()
        .body(hasXPath("//someNode[@attr='yes']"))
        .body(not(hasXPath("//someOther[@attr='no']")))
    .when().get("/xml");

What is the expected output? What do you see instead?

Specifically, the not(hasXPath()) call will return true, even if the xpath IS 
contained in the xml.  This may occur without chaining.  An even more clear 
example is to put .body(hasXPath(testString)).body(not(hasXPath(testString))) 
and that will pass, despite the obvious failure due to the contradiction.

What version of the product are you using? On what operating system?

1.6.2 on Windows and Linux

Please provide any additional information below.

Stepping into this with the debugger every step of the way changed the results 
versus just running it.  That could get chained calls to body(hasXPath()) to 
return false, even when they were true.  See attached image - that should have 
passed but failed only when debugged *every*step*of*the*way* (it was 
frustratingly slow).

Original issue reported on code.google.com by j...@roosterpark.com on 23 Jan 2013 at 7:54

Attachments:

GoogleCodeExporter commented 8 years ago
Do you get the same result with the latest version?

Original comment by johan.ha...@gmail.com on 27 Jan 2013 at 7:36

GoogleCodeExporter commented 8 years ago
Yes, I tried upgrading to 1.7.2 today and have the same problem, where:

        given()
            .spec(getRequest())
        .expect()
            .statusCode(200)
            .body(hasXPath(AN_XPATH))
            .body(not(hasXPath(AN_XPATH)))
            .body(not(hasXPath(ANOTHER_XPATH)))
        .when()
            .get("get");

passes.

Original comment by j...@roosterpark.com on 28 Jan 2013 at 8:10

GoogleCodeExporter commented 8 years ago
Alright thanks for trying it out. Could you give an example of the XML you're 
trying to test?

Original comment by johan.ha...@gmail.com on 29 Jan 2013 at 7:14

GoogleCodeExporter commented 8 years ago
Names have been changed to protect the innocent.. and the guilty.. But very 
normal XML, as below.  Basically testing that "delete" operations of inner 
nodes works, and at the time it didn't, but the tests said that it did.  That's 
how I discovered this.

<?xml version="1.0" encoding="UTF-8"?>
<user user-id="24985">
  <date-created>2008-11-17T08:00:00Z</date-created>
  <date-modified>2012-09-27T02:29:43.883Z</date-modified>
  <userFavorite application-id="1" favorite-id="28" userData="someData" sequence-number="1">
    <date-created>2011-01-20T19:59:47.887Z</date-created>
    <date-modified>2012-09-25T23:52:21.167Z</date-modified>
  </userFavorite>
</user>

Oh, junit version 4.10 is what's being used, FWIW, so very modern.

Original comment by j...@roosterpark.com on 30 Jan 2013 at 2:00

GoogleCodeExporter commented 8 years ago
Thanks!

Original comment by johan.ha...@gmail.com on 30 Jan 2013 at 7:08

GoogleCodeExporter commented 8 years ago
I've now fixed this in master.

Original comment by johan.ha...@gmail.com on 20 Nov 2013 at 2:27

GoogleCodeExporter commented 8 years ago

Original comment by johan.ha...@gmail.com on 22 Jan 2014 at 10:01