Search code examples
karatehessian

Best practices to test Hessian RPC requests with Karate


We're successfully using Karate to automate tests for REST and SOAP webservices. In addition, we're having some legacy webservices, which are based on the Hessian Web Service protocol (http://hessian.caucho.com/).

Hessian calls are HTTP requests as well, so we would like to add them to our Karate test suites.

My first attempt was to use the Java Interop feature, so the tests are implemeted as Java code and the Java classes are getting called within the Feature files.

Example:

Scenario: Test offer purchase order
  * def OfferPurchaseClient = Java.type('com.xyz.OfferPurchaseClient')
  * def orderId = OfferPurchaseClient.createOrder('12345', 'xyz', '[email protected]')
  * match orderId == '#number'

This approach is working, but I'm wondering if there is a more elegant way which would also use some more features of the Karate DSL.

I'm thinking about something like this (Dummy Code):

Scenario: Test offer purchase order
  Given url orderManagementEndpoint
  And path offerPurchase
  And request serializeHessian(offerPurchase.json)
  When method post
  Then status 200
  And match deserializeHessian(response).orderId == '#number'

Any recommendations/tips about how to implement such an approach?


Solution

  • I actually think you are already on the right track with the Java interop approach. The HTTP client is in my honest opinion a very small sub-set of the capabilities of Karate, there are so many other aspects such as assertions, reports, parallel-execution, even load-testing etc. So I wouldn't worry about not using request, method, status etc.

    Maybe OfferPurchaseClient.createOrder() can return a JSON.

    Or what I would do is consider an approach like OfferPurchaseClient.request(Map<String, Object> payload) - where payload can include all the parameters including the path and expected response code etc.

    To put this another way, I'm suggesting that you write your own mini-framework and custom DSL around some Java code. If you want inspiration and ideas, please look at this discussion, it is an example of building a CLI testing tool around Karate: https://stackoverflow.com/a/62911366/143475