-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to override the default simulation source in junit5 Hov…
…erflySimulate annotation
- Loading branch information
Showing
5 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ enum SourceType { | |
DEFAULT_PATH, | ||
CLASSPATH, | ||
URL, | ||
FILE | ||
FILE, | ||
EMPTY | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
junit5/src/test/java/io/specto/hoverfly/junit5/HoverflyBaseExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.specto.hoverfly.junit5; | ||
|
||
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson; | ||
|
||
import io.specto.hoverfly.junit.core.Hoverfly; | ||
import io.specto.hoverfly.junit.core.SslConfigurer; | ||
import java.io.IOException; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
// Should inherit the Hoverfly annotation from the base test. | ||
class HoverflyBaseExtensionTest extends HoverflyBaseTest { | ||
|
||
private static OkHttpClient client; | ||
|
||
@BeforeAll | ||
static void init(Hoverfly hoverfly) { | ||
SslConfigurer sslConfigurer = hoverfly.getSslConfigurer(); | ||
client = new OkHttpClient.Builder() | ||
.sslSocketFactory(sslConfigurer.getSslContext().getSocketFactory(), sslConfigurer.getTrustManager()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void shouldImportSimulationFromCustomSource() throws IOException { | ||
|
||
final Request request = new Request.Builder().url("https://www.my-test.com/api/bookings/1") | ||
.build(); | ||
|
||
final Response response = client.newCall(request).execute(); | ||
|
||
assertThatJson(response.body().string()).node("bookingId").isStringEqualTo("1"); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
junit5/src/test/java/io/specto/hoverfly/junit5/HoverflyBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.specto.hoverfly.junit5; | ||
|
||
import io.specto.hoverfly.junit.core.Hoverfly; | ||
import io.specto.hoverfly.junit.core.SimulationSource; | ||
import io.specto.hoverfly.junit5.api.HoverflySimulate; | ||
import io.specto.hoverfly.junit5.api.HoverflySimulate.Source; | ||
import io.specto.hoverfly.junit5.api.HoverflySimulate.SourceType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith({HoverflyExtension.class}) | ||
@HoverflySimulate(source = @Source(type = SourceType.EMPTY)) | ||
public abstract class HoverflyBaseTest { | ||
|
||
@BeforeEach | ||
void setUp(Hoverfly hoverfly) { | ||
hoverfly.reset(); | ||
hoverfly.simulate(SimulationSource.classpath("test-service-https.json")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters