From 0d1133720b6a3f759d0ace384ffbd858467c215a Mon Sep 17 00:00:00 2001 From: Tommy Situ Date: Fri, 19 Jul 2019 16:40:23 +0100 Subject: [PATCH] Document incremental capture option --- docs/pages/junit4/junit4.rst | 18 +++++++++++++++ .../hoverfly/ruletest/CaptureModeTest.java | 23 ++++++------------- .../ruletest/IncrementalCaptureTest.java | 7 ------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/pages/junit4/junit4.rst b/docs/pages/junit4/junit4.rst index db970e4f..17e58f4b 100644 --- a/docs/pages/junit4/junit4.rst +++ b/docs/pages/junit4/junit4.rst @@ -51,6 +51,24 @@ Multi-Capture File is relative to ``src/test/resources/hoverfly``. +.. _incrementalcapture: + +Incremental Capture +------------------- + +In capture mode, ``HoverflyRule`` by default exports the simulation and overwrites any existing content of the supplied file. +This is not very helpful if you add a new test and you don't want to re-capture everything. +In this case, you can enable the incremental capture option. ``HoverflyRule`` will check and import if the supplied simulation file exists. Any new request / response pairs will be appended to the existing file during capturing. + +.. code-block:: java + + @ClassRule + public static HoverflyRule hoverflyRule = HoverflyRule.inCaptureMode("simulation.json", + localConfigs() + .enableIncrementalCapture()); + + + .. _captureorsimulate: Capture or Simulate diff --git a/src/test/java/io/specto/hoverfly/ruletest/CaptureModeTest.java b/src/test/java/io/specto/hoverfly/ruletest/CaptureModeTest.java index 3014d2e4..fb2e24dd 100644 --- a/src/test/java/io/specto/hoverfly/ruletest/CaptureModeTest.java +++ b/src/test/java/io/specto/hoverfly/ruletest/CaptureModeTest.java @@ -6,22 +6,22 @@ import io.specto.hoverfly.junit.core.model.Simulation; import io.specto.hoverfly.junit.rule.HoverflyRule; import io.specto.hoverfly.webserver.CaptureModeTestWebServer; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Set; import org.json.JSONException; import org.junit.AfterClass; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.web.client.RestTemplate; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; + import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs; import static java.nio.charset.Charset.defaultCharset; import static org.assertj.core.api.Assertions.assertThat; @@ -70,13 +70,4 @@ public void shouldRecordInteractions() { restTemplate.getForObject(webServerBaseUrl, String.class); } - - @Test - @Ignore("Currently Not Supported") - public void shouldRecordOtherInteractions() { - // When - restTemplate.getForObject(webServerBaseUrl.toString() + "/other", String.class); - } - - } diff --git a/src/test/java/io/specto/hoverfly/ruletest/IncrementalCaptureTest.java b/src/test/java/io/specto/hoverfly/ruletest/IncrementalCaptureTest.java index 6cf45ef3..763e8a79 100644 --- a/src/test/java/io/specto/hoverfly/ruletest/IncrementalCaptureTest.java +++ b/src/test/java/io/specto/hoverfly/ruletest/IncrementalCaptureTest.java @@ -1,22 +1,15 @@ package io.specto.hoverfly.ruletest; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.io.Resources; import io.specto.hoverfly.junit.core.model.RequestResponsePair; import io.specto.hoverfly.junit.core.model.Simulation; import io.specto.hoverfly.junit.rule.HoverflyRule; import io.specto.hoverfly.webserver.CaptureModeTestWebServer; -import org.apache.commons.io.FileUtils; -import org.json.JSONException; import org.junit.*; -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.web.client.RestTemplate; import java.io.IOException; -import java.io.PrintWriter; import java.net.URI; -import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths;