Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify integer value in response header using REST-assured

perhaps due to my inexperience with rest-assured and hamcrest matchers I haven't managed to figure out how to do this assertion properly

  when().
      get(url).
  then().
      header("my-header", lessThanOrEqualTo("60")); // should compare Integers not Strings

An obvious solution would be to extract the value from header, convert it to Integer and then do the assertion manually. However that would kinda spoil the beauty of working with rest-assured. Is there a way to do the correct comparison without bloating the test?

like image 938
pseudo Avatar asked Jun 17 '15 21:06

pseudo


1 Answers

As of REST Assured 2.6.0 you can supply a mapping function as the second argument to the header method. For example you can make use of Java 8 method references like this:

when().
      get(url).
then().
      header("my-header", Integer::parseInt, lessThanOrEqualTo(60)); 
like image 121
Johan Avatar answered Nov 16 '22 21:11

Johan