Skip to content

Commit d6f861f

Browse files
patowntommysitu
authored andcommitted
Add enableIncrementalCapture in hoverfly-java-junit5
1 parent 2112e42 commit d6f861f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

junit5/src/main/java/io/specto/hoverfly/junit5/HoverflyExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.jupiter.api.extension.*;
1313

1414
import java.lang.reflect.AnnotatedElement;
15+
import java.nio.file.Files;
1516
import java.nio.file.Path;
1617

1718
import static io.specto.hoverfly.junit.core.HoverflyMode.SIMULATE;
@@ -59,6 +60,9 @@ public void beforeEach(ExtensionContext context) {
5960
hoverfly.simulate(source);
6061
}
6162
}
63+
if (hoverfly.getHoverflyConfig().isIncrementalCapture() && capturePath != null && Files.isReadable(capturePath)) {
64+
hoverfly.simulate(SimulationSource.file(capturePath));
65+
}
6266
}
6367

6468
@Override

junit5/src/main/java/io/specto/hoverfly/junit5/HoverflyExtensionUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static io.specto.hoverfly.junit.core.HoverflyConfig getHoverflyConfigs(HoverflyC
5353
((LocalHoverflyConfig) configs).addCommands(config.commands());
5454
}
5555
}
56-
fillHoverflyConfig(configs, config);
56+
setCommonHoverflyConfig(configs, config);
5757
return configs;
5858

5959
} else {
@@ -92,7 +92,7 @@ static Path getCapturePath(String path, String filename) {
9292
return Paths.get(path).resolve(filename);
9393
}
9494

95-
private static void fillHoverflyConfig(io.specto.hoverfly.junit.core.HoverflyConfig configs,
95+
private static void setCommonHoverflyConfig(io.specto.hoverfly.junit.core.HoverflyConfig configs,
9696
HoverflyConfig configParams) {
9797
configs
9898
.adminPort(configParams.adminPort())
@@ -112,6 +112,9 @@ private static void fillHoverflyConfig(io.specto.hoverfly.junit.core.HoverflyCon
112112
if (configParams.statefulCapture()) {
113113
configs.enableStatefulCapture();
114114
}
115+
if (configParams.enableIncrementalCapture()){
116+
configs.enableIncrementalCapture();
117+
}
115118
}
116119

117120
private static SimulationPreprocessor getSimulationPreprocessor(HoverflyConfig configParams) {

junit5/src/main/java/io/specto/hoverfly/junit5/api/HoverflyConfig.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
boolean plainHttpTunneling() default false;
8686

8787
/**
88-
* Configure Hoverfly to skip TLS verification. This option allows Hoverfly to perform insecure SSL connections to target server that uses invalid certificate (eg. self-signed certificate)
88+
* Configure Hoverfly to skip TLS verification. This option allows Hoverfly to perform "insecure" SSL connections to target server that uses invalid certificate (eg. self-signed certificate)
8989
*/
9090
boolean disableTlsVerification() default false;
9191

@@ -135,4 +135,13 @@
135135
* Overrides the default path for Hoverfly binary and working directory.
136136
*/
137137
String binaryLocation() default "";
138+
139+
/**
140+
* By default Hoverfly exports the captured requests and responses to a new file by replacing any existing one. Enable this
141+
* option to import any existing simulation file and append new requests to it in capture mode.
142+
* @return the {@link io.specto.hoverfly.junit.core.HoverflyConfig} for further customizations
143+
*/
144+
145+
boolean enableIncrementalCapture() default false;
146+
138147
}

junit5/src/test/java/io/specto/hoverfly/junit5/HoverflyConfigTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ void shouldUseDefaultValues(Hoverfly hoverfly) {
5959
webServer = true, statefulCapture = true,
6060
simulationPreprocessor = CustomSimulationPreprocessor.class,
6161
commands = { "-log-level", "error" },
62-
logLevel = LogLevel.DEBUG
62+
logLevel = LogLevel.DEBUG,
63+
enableIncrementalCapture =true
6364
))
6465
@ExtendWith(HoverflyExtension.class)
6566
class CustomizedSettings {
@@ -80,6 +81,7 @@ void shouldUseCustomizedValues(Hoverfly hoverfly) {
8081
assertThat(configs.getSimulationPreprocessor()).isPresent();
8182
assertThat(configs.getCommands()).containsExactly("-log-level", "error");
8283
assertThat(configs.getLogLevel()).isEqualTo(Optional.of(LogLevel.DEBUG));
84+
assertThat(configs.isIncrementalCapture()).isTrue();
8385
}
8486

8587
}

0 commit comments

Comments
 (0)