Skip to content

Commit 7973bc7

Browse files
committed
#236 add binaryLocation to Junit5 extension config
1 parent a08290e commit 7973bc7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static io.specto.hoverfly.junit.core.HoverflyConfig getHoverflyConfigs(HoverflyC
4040
.enableClientAuth(config.clientCertPath(), config.clientKeyPath(), config.clientAuthDestination())
4141
.clientAuthCaCertPath(config.clientCaCertPath());
4242
}
43+
if (StringUtils.isNotBlank(config.binaryLocation())) {
44+
((LocalHoverflyConfig) configs).binaryLocation(config.binaryLocation());
45+
}
4346
if (config.plainHttpTunneling()) {
4447
((LocalHoverflyConfig) configs).plainHttpTunneling();
4548
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@
130130
* Client CA certificate file in classpath. Must be a PEM encoded certificate, with .crt or .pem extensions
131131
*/
132132
String clientCaCertPath() default "";
133+
134+
/**
135+
* Overrides the default path for Hoverfly binary and working directory.
136+
*/
137+
String binaryLocation() default "";
133138
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void shouldUseDefaultValues(Hoverfly hoverfly) {
4848
assertThat(configs.getClientKeyPath()).isNull();
4949
assertThat(configs.getClientAuthDestination()).isNull();
5050
assertThat(configs.getClientCaCertPath()).isNull();
51+
assertThat(configs.getBinaryLocation()).isNull();
5152
}
5253
}
5354

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.specto.hoverfly.junit5;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.mockito.Mockito.doReturn;
5+
import static org.mockito.Mockito.mock;
6+
import static org.mockito.Mockito.when;
7+
8+
import io.specto.hoverfly.junit.core.config.HoverflyConfiguration;
9+
import io.specto.hoverfly.junit5.api.HoverflyConfig;
10+
import io.specto.hoverfly.junit5.api.UnsetSimulationPreprocessor;
11+
import org.junit.jupiter.api.Test;
12+
13+
class HoverflyExtensionUtilsTest {
14+
15+
@Test
16+
void shouldBeAbleToCustomizeBinaryLocation() {
17+
18+
// testing with mock file directory is easier
19+
HoverflyConfig mockHoverflyConfig = mock(HoverflyConfig.class);
20+
// mock default values
21+
when(mockHoverflyConfig.remoteHost()).thenReturn("");
22+
when(mockHoverflyConfig.captureHeaders()).thenReturn(new String[]{});
23+
when(mockHoverflyConfig.commands()).thenReturn(new String[]{});
24+
when(mockHoverflyConfig.destination()).thenReturn(new String[]{});
25+
doReturn(UnsetSimulationPreprocessor.class).when(mockHoverflyConfig).simulationPreprocessor();
26+
when(mockHoverflyConfig.binaryLocation()).thenReturn("/home/hoverfly");
27+
28+
HoverflyConfiguration actualConfigs = HoverflyExtensionUtils.getHoverflyConfigs(mockHoverflyConfig).build();
29+
30+
assertThat(actualConfigs.getBinaryLocation()).isEqualTo("/home/hoverfly");
31+
}
32+
}

0 commit comments

Comments
 (0)