Skip to content

feature request - convert hoverfly capture into junit test #853

Open

Description

@felixvolz

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.

Activity

  1. tommysitu commented on Jun 20, 2019

    @tommysitu
    Member

    @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.

  2. felixvolz commented on Jun 20, 2019

    @felixvolz
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions