Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karate MockServer enhancement to support non http protocols like JMS, GRPC, GraphQL or any other custom protocol #2606

Open
naveenchandra91 opened this issue Sep 3, 2024 · 4 comments
Labels

Comments

@naveenchandra91
Copy link

naveenchandra91 commented Sep 3, 2024

Firstly kudos for Karate library to develop a fantastic Over the wire test double mocking which is unparalleled in terms of capabilities. Its simple and straightforward and I was able to mock a sample http service in a matter of hours!

Similarly I want to mock sample services which are of different protocols like JMS. I would want the ability for karate to listen to JMS server and intercept the call and forward/mock the api call and return response. Currently I dont think it is supported. But It should be possible with some changes to MockServer and other enhancements.(Would love to raise a PR for this).

I can think of the following changes to support this enhancement(I might be wrong, please suggest other ideas/improvements):

  1. Modify MockServer extends HttpServer and add a Strategy pattern based support
    to add multiple protocols implementation like JMS, GRPC, GraphQL or any custom protocol(User can pass the java interop during runtime to establish how he wants the connection or protocol to be handled)
  2. Modify MockServer builder to add methods for protocol like JMS, GRPC, GraphQL or Custom Protocol(Karate acts like a SocketServer, rest of the protocol details provided by user via Java Interop)
  3. Dont spin up a HttpServer if http builder method is not called. Instead use a port method for Karate to listen to connection requests. And let the user decide the connection protocol should be.
  4. Ensure http connections works as is currently if http builder method is called.
  5. Enhance karate.proceed proxying for other protocols. We can enhance proceed function to take custom java interop function to let user decide how proxying should happen.
  6. Add more generic convenience functions like pathMatches for other protocols so that karate can intercept the server requests for proxying or mocking the response.
@ptrthomas
Copy link
Member

ptrthomas commented Sep 5, 2024

@naveenchandra91 thanks for the kind comments. as you can imagine it is hard to generalize mocks, so one point of view is that teams can build their own with little effort following the example here: https://x.com/getkarate/status/1417023536082812935

the other point is that we have commercial extensions for async protocols now, and mocks may eventually be part of that - but we don't see a critical mass of teams needing it

@ptrthomas
Copy link
Member

closing, and as always - a PR can be submitted against this issue

@ptrthomas
Copy link
Member

reopening for discussion

@naveenchandra91 wow that seems to be a lot of work. I am super busy at the moment so this may take time to get to.

took a quick look and my main feedback is that it is hard to understand what this looks like for a real test from an end-user perspective and there has to be some examples also, you can refer to how we have tests for all kinds of things under karate-demo

@ptrthomas ptrthomas reopened this Feb 18, 2025
@naveenchandra91
Copy link
Author

@ptrthomas : Appreciate the feedback. I will add sample end-user tests in karate-demo for MQ(With current generic mock. Plugin based to be added once the implementation done) and Fix Server protocol mock(Very niche, just to show how any custom protocol can be mocked as per needs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants