hoverfly-java icon indicating copy to clipboard operation
hoverfly-java copied to clipboard

CaptureMode should not override the whole simlucation.json file

Open howareyouo opened this issue 5 years ago • 4 comments

For example i have a class :

public class ControllerTest  {
  @ClassRule
  public static HoverflyRule hoverflyRule = HoverflyRule.inCaptureMode("simulation.json");

  @Test
  public void reqeustOne() {
      httpClient.get('/url_one')
  }

  @Test
  public void reqeustTwo() {
      httpClient.get('/url_two')
  }
}

If I run test in class level, the result was fine. And if I run requestOne first then requestTwo after, only requestTwo will be export to simulation.json file, hoverfly-java just simply override the existing file, this is not I was expecting. It should be override/append the content by request mathing described in the docs.

This will be the issue for inCaptureOrSimulateMode as well: It should be not just detecting the file extists or not, but looking into the content, to see was there a matched request exists, is it does, simulate it, if not , capturing then append to the json file.

And by the way, great tools, keeping up guys !!

howareyouo avatar Jun 20 '19 07:06 howareyouo

Thank you for your feedback! I believe this issue is related to this one: https://github.com/SpectoLabs/hoverfly-java/issues/123

We can perhaps add an option to check existing simulation and append to it when you run a test.

tommysitu avatar Jun 24 '19 12:06 tommysitu

An option allowing you to do incremental capture is available in 0.12.1: https://docs.hoverfly.io/projects/hoverfly-java/en/latest/pages/junit4/junit4.html#incremental-capture

tommysitu avatar Jul 23 '19 15:07 tommysitu

Just tested it, the enableIncrementalCapture() feature works fine with inCaptureMode, but not compatible with inCaptureOrSimulationMode.

I still have to manually change the code to the inCaptureMode mode when adding new tests.

I was wondering why not add this feature to all these modes once for all ?

howareyouo avatar Aug 20 '19 11:08 howareyouo

It requires a change to the core Hoverfly project to do what you wanted. That's why I am keeping this issue open. You can keep an eye on this one: https://github.com/SpectoLabs/hoverfly/issues/864

tommysitu avatar Aug 20 '19 11:08 tommysitu