rest-assured: Cannot compare Long values within body
As already faced in https://groups.google.com/forum/#!topic/rest-assured/mf-VIHM-aJA, a body element cannot be compared to a long value.
I think the best solution could be to allow function passing (as for headers) in order to convert the value to a long. E.g:
long expected = 1L;
when().get("/test/{id}", expected).
then().body("id",Long::valueOf, Matchers.is(expected));
At the moment I have to compare the id value with an integer version of expected that is definitely unsafe…
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 8
- Comments: 32
This is a Hamcrest matching issue and could be easily fixed using Hamcrest
ComparatorMatcherBuilder.Assuming this JSON as REST response, note the “salary” property having integer and double values:
To safely compare them, try to create a custom matcher that parses the values BEFORE comparing:
As it is not a RestAssured issue, I think you could close it.
Yes I mean exactly that. At the moment I solved the problem transforming the entire body to the response class and checking with assertions the object state. E.g.:
Yes I’ve been thinking about function passing as well. The problem is that the api already supports the use of path arguments which will make the API twice as big if adding functions as well. I have been thinking about making “arguments” more general so that it would be possible to supply a “mapper function argument”. Maybe like this:
Where
mapreturns another implementation of theArgumentclass (probablyArgumentwould implement another interface that can be common for all types (map,withArgsetc)).