Class WireMockExtension
- java.lang.Object
-
- com.github.tomakehurst.wiremock.junit.DslWrapper
-
- com.github.tomakehurst.wiremock.junit5.WireMockExtension
-
- All Implemented Interfaces:
Admin
,Stubbing
,org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
public class WireMockExtension extends DslWrapper implements org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.AfterAllCallback
JUnit Jupiter extension that manages a WireMock server instance's lifecycle and configuration. See http://wiremock.org/docs/junit-jupiter/ for full documentation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WireMockExtension.Builder
-
Field Summary
-
Fields inherited from class com.github.tomakehurst.wiremock.junit.DslWrapper
admin, stubbing
-
-
Constructor Summary
Constructors Modifier Constructor Description WireMockExtension()
protected
WireMockExtension(WireMockExtension.Builder builder)
Constructor intended for subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
java.lang.String
baseUrl()
void
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
static WireMockExtension.Builder
extensionOptions()
Alias fornewInstance()
for use with custom subclasses, with a more relevant name for that use.int
getHttpsPort()
int
getPort()
WireMockRuntimeInfo
getRuntimeInfo()
static WireMockExtension.Builder
newInstance()
Create a new builder for the extension.protected void
onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.protected void
onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-test cleanup of WireMock and its associated resources.protected void
onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-class WireMock setup.protected void
onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-test WireMock setup.java.lang.Object
resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
boolean
supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
java.lang.String
url(java.lang.String path)
-
Methods inherited from class com.github.tomakehurst.wiremock.junit.DslWrapper
addStubMapping, countRequestsMatching, editStub, editStubMapping, findAll, findAllNearMissesFor, findAllStubsByMetadata, findAllUnmatchedRequests, findNearMissesFor, findNearMissesForAllUnmatchedRequests, findNearMissesForUnmatchedRequests, findRequestsMatching, findStubMappingsByMetadata, findTopNearMissesFor, findTopNearMissesFor, findUnmatchedRequests, getAllScenarios, getAllServeEvents, getGlobalSettings, getOptions, getRecordingStatus, getServedStub, getServeEvents, getServeEvents, getSingleStubMapping, getStubMapping, getStubMappings, givenThat, importStubs, listAllStubMappings, removeServeEvent, removeServeEventsForStubsMatchingMetadata, removeServeEventsMatching, removeStub, removeStub, removeStubMapping, removeStubMapping, removeStubMappingsByMetadata, removeStubsByMetadata, resetAll, resetMappings, resetRequests, resetScenario, resetScenarios, resetToDefaultMappings, saveMappings, setGlobalFixedDelay, setScenarioState, shutdownServer, snapshotRecord, snapshotRecord, snapshotRecord, startRecording, startRecording, startRecording, stopRecording, stubFor, updateGlobalSettings, verify, verify, verify
-
-
-
-
Constructor Detail
-
WireMockExtension
public WireMockExtension()
-
WireMockExtension
protected WireMockExtension(WireMockExtension.Builder builder)
Constructor intended for subclasses. The parameter is a builder so that we can avoid a constructor explosion or backwards-incompatible changes when new options are added.- Parameters:
builder
- aWireMockExtension.Builder
instance holding the initialisation parameters for the extension.
-
-
Method Detail
-
extensionOptions
public static WireMockExtension.Builder extensionOptions()
Alias fornewInstance()
for use with custom subclasses, with a more relevant name for that use.- Returns:
- a new
WireMockExtension.Builder
instance.
-
newInstance
public static WireMockExtension.Builder newInstance()
Create a new builder for the extension.- Returns:
- a new
WireMockExtension.Builder
instance.
-
onBeforeAll
protected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-class WireMock setup.- Parameters:
wireMockRuntimeInfo
- port numbers, base URLs and HTTPS info for the running WireMock instance/
-
onBeforeEach
protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-test WireMock setup.- Parameters:
wireMockRuntimeInfo
- port numbers, base URLs and HTTPS info for the running WireMock instance/
-
onAfterEach
protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-test cleanup of WireMock and its associated resources.- Parameters:
wireMockRuntimeInfo
- port numbers, base URLs and HTTPS info for the running WireMock instance/
-
onAfterAll
protected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo)
To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.- Parameters:
wireMockRuntimeInfo
- port numbers, base URLs and HTTPS info for the running WireMock instance/
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
- Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public java.lang.Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
- Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
beforeAll
public final void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
java.lang.Exception
-
beforeEach
public final void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
java.lang.Exception
-
afterAll
public final void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
- Throws:
java.lang.Exception
-
afterEach
public final void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
java.lang.Exception
-
getRuntimeInfo
public WireMockRuntimeInfo getRuntimeInfo()
-
baseUrl
public java.lang.String baseUrl()
-
url
public java.lang.String url(java.lang.String path)
-
getHttpsPort
public int getHttpsPort()
-
getPort
public int getPort()
-
-