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

feature request - convert hoverfly capture into junit test #853

Open
felixvolz opened this issue Jun 19, 2019 · 2 comments
Open

feature request - convert hoverfly capture into junit test #853

felixvolz opened this issue Jun 19, 2019 · 2 comments

Comments

@felixvolz
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I follow a 'contract-first' design approach for APIs. This involves writing a contract (WSDL, swagger etc) first then implementing in a particular technology (e.g. java microservice, pega etc etc)

I have used hoverfly as a proxy to capture requests to an existing API. Capturing requests is great.

I am uplifting an API to use a new technology (i.e. same Contract, new implementation). It would be great if I could

  1. use hoverfly as a proxy to capture requests to the existing API
  2. use hoverfly to generate junit tests based on the simulation.json
  3. replay the junit tests agaisnt the new API (same contract, new implementation)

I currently manually capture requests/responses and manually write junit tests to invoke the new api. It seems like hoverfly has all the moving parts to automate the creation of unit tests for me.

Any suggestions to automate this workflow?

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@tommysitu
Copy link
Member

tommysitu commented Jun 20, 2019

@felixvolz That's a good idea. We have actually done some work on our cloud platform to generate curl commands from a simulation using this tool: https://github.com/Kong/httpsnippet.

The tool can also generate OkHttp or Unirest client code for Java from a HAR file. Here is a conversion of an example HAR file:

httpsnippet example.json --target java --client okhttp --output ./snippets

The output JAVA snippets look like this:

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "foo=bar");
Request request = new Request.Builder()
  .url("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
  .post(body)
  .addHeader("cookie", "foo=bar; bar=baz")
  .addHeader("accept", "application/json")
  .addHeader("content-type", "application/x-www-form-urlencoded")
  .build();

Response response = client.newCall(request).execute();

It doesn't create a JUnit class though.

Converting journal to HAR is probably easier, and hoverfly should be able to output journal in a HAR format, making it compatible with many HAR adaptors as well.

@felixvolz
Copy link
Author

Interesting! Thx for the comprehensive info!

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

No branches or pull requests

2 participants