简体   繁体   English

使用REST-assured验证响应头中的整数值

[英]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 也许是由于我对有保证和Hamcrest匹配器的经验不足,我还没有设法弄清楚如何正确地做这个断言

  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. 一个明显的解决方案是从头中提取值,将其转换为Integer,然后手动执行断言。 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? 有没有办法在没有膨胀测试的情况下进行正确的比较?

As of REST Assured 2.6.0 you can supply a mapping function as the second argument to the header method. 从REST Assured 2.6.0开始,您可以提供映射函数作为header方法的第二个参数。 For example you can make use of Java 8 method references like this: 例如,您可以使用Java 8方法引用,如下所示:

when().
      get(url).
then().
      header("my-header", Integer::parseInt, lessThanOrEqualTo(60)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM