Verify integer value in response header using REST-assured

3k views Asked by At

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?

1

There are 1 answers

1
Johan On BEST ANSWER

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));