Class WireMockExtension

java.lang.Object
com.github.tomakehurst.wiremock.junit.DslWrapper
com.github.tomakehurst.wiremock.junit5.WireMockExtension
All Implemented Interfaces:
com.github.tomakehurst.wiremock.core.Admin, com.github.tomakehurst.wiremock.junit.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, org.junit.jupiter.api.extension.TestInstantiationAwareExtension

public class WireMockExtension extends com.github.tomakehurst.wiremock.junit.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 
     

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Field Summary

    Fields inherited from class com.github.tomakehurst.wiremock.junit.DslWrapper

    admin, stubbing
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor intended for subclasses.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    final void
    afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
     
    final void
    beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
     
    final void
    beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
     
    Alias for newInstance() for use with custom subclasses, with a more relevant name for that use.
    int
     
    int
     
     
    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
    onAfterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, 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
    onAfterEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
    To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.
    protected void
    onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo)
    To be overridden in subclasses in order to run code immediately after per-class WireMock setup.
    protected void
    onBeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, 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.
    protected void
    onBeforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
    To be overridden in subclasses in order to run code immediately after per-test cleanup of WireMock and its associated resources.
    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)
     
    url(String path)
     

    Methods inherited from class com.github.tomakehurst.wiremock.junit.DslWrapper

    addMessageStubMapping, addStubMapping, countMessageEventsMatching, countRequestsMatching, editStub, editStubMapping, findAll, findAllMessageEvents, findAllMessageStubsByMetadata, findAllNearMissesFor, findAllStubsByMetadata, findAllUnmatchedRequests, findMessageEventsMatching, findNearMissesFor, findNearMissesForAllUnmatchedRequests, findNearMissesForUnmatchedRequests, findRequestsMatching, findStubMappingsByMetadata, findTopNearMissesFor, findTopNearMissesFor, findUnmatchedRequests, findUnmatchedStubs, getAllMessageServeEvents, getAllScenarios, getAllServeEvents, getGlobalSettings, getMessageServeEvent, getMessageServeEvents, getMessageStubMappingsList, getOptions, getRecordingStatus, getServedStub, getServeEvents, getServeEvents, getSingleStubMapping, getStubMapping, getStubMappings, givenThat, importStubs, listAllMessageChannels, listAllMessageStubMappings, listAllStubMappings, messageStubFor, messageStubFor, removeMessageServeEvent, removeMessageServeEventsForStubsMatchingMetadata, removeMessageServeEventsMatching, removeMessageStub, removeMessageStubMapping, removeMessageStubsByMetadata, removeServeEvent, removeServeEventsForStubsMatchingMetadata, removeServeEventsMatching, removeStub, removeStub, removeStub, removeStubMapping, removeStubMapping, removeStubMappings, removeStubMappingsByMetadata, removeStubsByMetadata, resetAll, resetMappings, resetMessageJournal, resetMessageStubMappings, resetMessageStubs, resetRequests, resetScenario, resetScenarios, resetToDefaultMappings, saveMappings, sendChannelMessage, setGlobalFixedDelay, setScenarioState, shutdownServer, snapshotRecord, snapshotRecord, snapshotRecord, startRecording, startRecording, startRecording, stopRecording, stubFor, updateGlobalSettings, verify, verify, verify, verifyMessageEvent, verifyMessageEvent, verifyMessageEvent, waitForMessageEvent, waitForMessageEvents

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.github.tomakehurst.wiremock.core.Admin

    sendChannelMessage

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • 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 - a WireMockExtension.Builder instance holding the initialisation parameters for the extension.
  • Method Details

    • extensionOptions

      public static WireMockExtension.Builder extensionOptions()
      Alias for newInstance() 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/
    • onBeforeAll

      protected void onBeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
      To be overridden in subclasses in order to run code immediately after per-class WireMock setup.
      Parameters:
      extensionContext - the current extension context; never null
      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/
    • onBeforeEach

      protected void onBeforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
      To be overridden in subclasses in order to run code immediately after per-test cleanup of WireMock and its associated resources.
      Parameters:
      extensionContext - the current extension context; never null
      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/
    • onAfterEach

      protected void onAfterEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
      To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.
      Parameters:
      extensionContext - the current extension context; never null
      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/
    • onAfterAll

      protected void onAfterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext, WireMockRuntimeInfo wireMockRuntimeInfo)
      To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.
      Parameters:
      extensionContext - the current extension context; never null
      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 interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • resolveParameter

      public 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 interface org.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 Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • beforeEach

      public final void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Throws:
      Exception
    • afterAll

      public final void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • afterEach

      public final void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      Throws:
      Exception
    • getRuntimeInfo

      public WireMockRuntimeInfo getRuntimeInfo()
    • baseUrl

      public String baseUrl()
    • url

      public String url(String path)
    • getHttpsPort

      public int getHttpsPort()
    • getPort

      public int getPort()