如何使用空手道测试其余端点以AVRO格式给出响应?

如何使用空手道测试其余端点以AVRO格式给出响应?

问题描述:

空手道对于验证提供json响应的rest api很有帮助.现在,我们有了api,可让我们以avro格式进行响应.可能还需要以avro格式发送有效负载.我如何使用空手道测试其余端点以AVRO格式给出响应?有什么简单的方法可以调整并完成它.谢谢!

Karate has been super helpful to validate our rest apis which gives json response. Now we have apis which gives us response in avro format. May also need to send the payload in avro format. How can i test the rest endpoints which gives response in AVRO format using karate? Is there any easy way I can tweak and get it done. Thanks!

这是我的建议,我认为这会很好地工作.

Here's my suggestion, and in my opinion this will work very well.

编写一个简单的Java实用程序,也许是一个静态方法,可以将JSON转换为AVRO,反之亦然.

Write a simple Java utility, maybe a static method that can take JSON and convert it to AVRO and vice versa.

现在您可以将所有请求数据定义为JSON-但在向服务器发出请求之前,请将其转换为AVRO.我不确定服务器调用是否为HTTP.如果是HTTP,那么您就知道如何在空手道中做什么,只需将二进制文件作为请求正文等发送即可.

Now you can define all your request data as JSON - but just before you make the request to the server, convert it to AVRO. I am not sure if the server call is HTTP or not. If it is HTTP - then you know what to do in Karate, just send binary as the request body etc.

否则,您甚至可能甚至没有使用空手道HTTP DSL,例如 method request 等.您还必须编写一个Java辅助程序来获取JSON(或AVRO)并调用服务器(特定于您的项目)并返回响应,并将其转换回JSON.例如:

Else you may not even use the Karate HTTP DSL like method, request etc. You have to write one more Java helper that will take your JSON (or AVRO) and make the call to the server (specific for your project) and return the response, converted back to JSON. For example:

* def Utils = Java.type('com.myco.avro.Utils')
* def json = { hello: 'world' }
* def req = Utils.toAvro(json)
* def res = Utils.send(req)
# you can combine this with the above
* def response = Utils.fromAvro(res)
* match response == { success: true }

是的,您可能主要将空手道用于匹配,报告,环境等.这仍然很有价值!许多人没有意识到HTTP只是Karate可以为您提供的功能的10%.

Yes, you might be using Karate mostly for matching, reporting, environments etc. Which is still valuable ! Many people don't realize that HTTP is just 10% of what Karate can do for you.