Class WireMockRule

  • All Implemented Interfaces:
    com.github.tomakehurst.wiremock.core.Admin, com.github.tomakehurst.wiremock.core.Container, com.github.tomakehurst.wiremock.junit.Stubbing, org.junit.rules.MethodRule, org.junit.rules.TestRule

    public class WireMockRule
    extends Object
    implements org.junit.rules.MethodRule, org.junit.rules.TestRule, com.github.tomakehurst.wiremock.core.Container, com.github.tomakehurst.wiremock.junit.Stubbing, com.github.tomakehurst.wiremock.core.Admin
    Author:
    Liam Newman
    • Constructor Summary

      Constructors 
      Constructor Description
      WireMockRule()  
      WireMockRule​(int port)  
      WireMockRule​(int port, Integer httpsPort)  
      WireMockRule​(com.github.tomakehurst.wiremock.core.Options options)  
      WireMockRule​(com.github.tomakehurst.wiremock.core.Options options, boolean failOnUnmatchedRequests)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMockServiceRequestListener​(com.github.tomakehurst.wiremock.http.RequestListener listener)  
      void addStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)  
      protected void after()  
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)  
      String baseUrl()  
      protected void before()  
      com.github.tomakehurst.wiremock.verification.VerificationResult countRequestsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)  
      void editStub​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)  
      void editStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)  
      void enableRecordMappings​(com.github.tomakehurst.wiremock.common.FileSource mappingsFileSource, com.github.tomakehurst.wiremock.common.FileSource filesFileSource)  
      List<com.github.tomakehurst.wiremock.verification.LoggedRequest> findAll​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)  
      List<com.github.tomakehurst.wiremock.verification.NearMiss> findAllNearMissesFor​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)  
      com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult findAllStubsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)  
      List<com.github.tomakehurst.wiremock.verification.LoggedRequest> findAllUnmatchedRequests()  
      List<com.github.tomakehurst.wiremock.verification.NearMiss> findNearMissesFor​(com.github.tomakehurst.wiremock.verification.LoggedRequest loggedRequest)  
      List<com.github.tomakehurst.wiremock.verification.NearMiss> findNearMissesForAllUnmatchedRequests()  
      com.github.tomakehurst.wiremock.verification.FindNearMissesResult findNearMissesForUnmatchedRequests()  
      com.github.tomakehurst.wiremock.verification.FindRequestsResult findRequestsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)  
      List<com.github.tomakehurst.wiremock.stubbing.StubMapping> findStubMappingsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)  
      com.github.tomakehurst.wiremock.verification.FindNearMissesResult findTopNearMissesFor​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)  
      com.github.tomakehurst.wiremock.verification.FindNearMissesResult findTopNearMissesFor​(com.github.tomakehurst.wiremock.verification.LoggedRequest loggedRequest)  
      com.github.tomakehurst.wiremock.verification.FindRequestsResult findUnmatchedRequests()  
      com.github.tomakehurst.wiremock.admin.model.GetScenariosResult getAllScenarios()  
      List<com.github.tomakehurst.wiremock.stubbing.ServeEvent> getAllServeEvents()  
      com.github.tomakehurst.wiremock.admin.model.GetGlobalSettingsResult getGlobalSettings()  
      com.github.tomakehurst.wiremock.global.GlobalSettingsHolder getGlobalSettingsHolder()  
      String getMethodName()  
      com.github.tomakehurst.wiremock.core.Options getOptions()  
      com.github.tomakehurst.wiremock.recording.RecordingStatusResult getRecordingStatus()  
      com.github.tomakehurst.wiremock.admin.model.SingleServedStubResult getServedStub​(UUID id)  
      com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult getServeEvents()  
      com.github.tomakehurst.wiremock.stubbing.StubMapping getSingleStubMapping​(UUID id)  
      com.github.tomakehurst.wiremock.admin.model.SingleStubMappingResult getStubMapping​(UUID id)  
      List<com.github.tomakehurst.wiremock.stubbing.StubMapping> getStubMappings()  
      com.github.tomakehurst.wiremock.stubbing.StubMapping givenThat​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)  
      int httpsPort()  
      void importStubs​(com.github.tomakehurst.wiremock.stubbing.StubImport stubImport)  
      boolean isRunning()  
      com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult listAllStubMappings()  
      void loadMappingsUsing​(com.github.tomakehurst.wiremock.standalone.MappingsLoader mappingsLoader)  
      int port()  
      void removeServeEvent​(UUID uuid)  
      com.github.tomakehurst.wiremock.verification.FindServeEventsResult removeServeEventsForStubsMatchingMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern stringValuePattern)  
      com.github.tomakehurst.wiremock.verification.FindServeEventsResult removeServeEventsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)  
      void removeStub​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)  
      void removeStub​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)  
      void removeStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)  
      void removeStubMappingsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)  
      void removeStubsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)  
      void resetAll()  
      void resetMappings()  
      void resetRequests()  
      void resetScenarios()  
      void resetToDefaultMappings()  
      void saveMappings()  
      void setGlobalFixedDelay​(int milliseconds)  
      void shutdown()  
      void shutdownServer()  
      com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord()  
      com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord​(com.github.tomakehurst.wiremock.recording.RecordSpec spec)  
      com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord​(com.github.tomakehurst.wiremock.recording.RecordSpecBuilder spec)  
      void start()  
      void startRecording​(com.github.tomakehurst.wiremock.recording.RecordSpec spec)  
      void startRecording​(com.github.tomakehurst.wiremock.recording.RecordSpecBuilder recordSpec)  
      void startRecording​(String targetBaseUrl)  
      void stop()  
      com.github.tomakehurst.wiremock.recording.SnapshotRecordResult stopRecording()  
      com.github.tomakehurst.wiremock.stubbing.StubMapping stubFor​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)  
      void updateGlobalSettings​(com.github.tomakehurst.wiremock.global.GlobalSettings newSettings)  
      String url​(String path)  
      void verify​(int count, com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)  
      void verify​(com.github.tomakehurst.wiremock.client.CountMatchingStrategy countMatchingStrategy, com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)  
      void verify​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)  
    • Constructor Detail

      • WireMockRule

        public WireMockRule​(com.github.tomakehurst.wiremock.core.Options options)
      • WireMockRule

        public WireMockRule​(com.github.tomakehurst.wiremock.core.Options options,
                            boolean failOnUnmatchedRequests)
      • WireMockRule

        public WireMockRule​(int port)
      • WireMockRule

        public WireMockRule​(int port,
                            Integer httpsPort)
      • WireMockRule

        public WireMockRule()
    • Method Detail

      • getMethodName

        public String getMethodName()
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runners.model.FrameworkMethod method,
                                                       Object target)
        Specified by:
        apply in interface org.junit.rules.MethodRule
      • before

        protected void before()
      • after

        protected void after()
      • loadMappingsUsing

        public void loadMappingsUsing​(com.github.tomakehurst.wiremock.standalone.MappingsLoader mappingsLoader)
      • getGlobalSettingsHolder

        public com.github.tomakehurst.wiremock.global.GlobalSettingsHolder getGlobalSettingsHolder()
      • addMockServiceRequestListener

        public void addMockServiceRequestListener​(com.github.tomakehurst.wiremock.http.RequestListener listener)
      • enableRecordMappings

        public void enableRecordMappings​(com.github.tomakehurst.wiremock.common.FileSource mappingsFileSource,
                                         com.github.tomakehurst.wiremock.common.FileSource filesFileSource)
      • stop

        public void stop()
      • start

        public void start()
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface com.github.tomakehurst.wiremock.core.Container
      • port

        public int port()
        Specified by:
        port in interface com.github.tomakehurst.wiremock.core.Container
      • httpsPort

        public int httpsPort()
      • baseUrl

        public String baseUrl()
      • isRunning

        public boolean isRunning()
      • givenThat

        public com.github.tomakehurst.wiremock.stubbing.StubMapping givenThat​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)
        Specified by:
        givenThat in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • stubFor

        public com.github.tomakehurst.wiremock.stubbing.StubMapping stubFor​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)
        Specified by:
        stubFor in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • editStub

        public void editStub​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)
        Specified by:
        editStub in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • removeStub

        public void removeStub​(com.github.tomakehurst.wiremock.client.MappingBuilder mappingBuilder)
        Specified by:
        removeStub in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • removeStub

        public void removeStub​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)
        Specified by:
        removeStub in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • getStubMappings

        public List<com.github.tomakehurst.wiremock.stubbing.StubMapping> getStubMappings()
        Specified by:
        getStubMappings in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • getSingleStubMapping

        public com.github.tomakehurst.wiremock.stubbing.StubMapping getSingleStubMapping​(UUID id)
        Specified by:
        getSingleStubMapping in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findStubMappingsByMetadata

        public List<com.github.tomakehurst.wiremock.stubbing.StubMapping> findStubMappingsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)
        Specified by:
        findStubMappingsByMetadata in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • removeStubMappingsByMetadata

        public void removeStubMappingsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)
        Specified by:
        removeStubMappingsByMetadata in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • removeStubMapping

        public void removeStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)
        Specified by:
        removeStubMapping in interface com.github.tomakehurst.wiremock.core.Admin
      • verify

        public void verify​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)
        Specified by:
        verify in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • verify

        public void verify​(int count,
                           com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)
        Specified by:
        verify in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • verify

        public void verify​(com.github.tomakehurst.wiremock.client.CountMatchingStrategy countMatchingStrategy,
                           com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)
        Specified by:
        verify in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findAll

        public List<com.github.tomakehurst.wiremock.verification.LoggedRequest> findAll​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)
        Specified by:
        findAll in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • getAllServeEvents

        public List<com.github.tomakehurst.wiremock.stubbing.ServeEvent> getAllServeEvents()
        Specified by:
        getAllServeEvents in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • setGlobalFixedDelay

        public void setGlobalFixedDelay​(int milliseconds)
        Specified by:
        setGlobalFixedDelay in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findAllUnmatchedRequests

        public List<com.github.tomakehurst.wiremock.verification.LoggedRequest> findAllUnmatchedRequests()
        Specified by:
        findAllUnmatchedRequests in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findNearMissesForAllUnmatchedRequests

        public List<com.github.tomakehurst.wiremock.verification.NearMiss> findNearMissesForAllUnmatchedRequests()
        Specified by:
        findNearMissesForAllUnmatchedRequests in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findAllNearMissesFor

        public List<com.github.tomakehurst.wiremock.verification.NearMiss> findAllNearMissesFor​(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder requestPatternBuilder)
        Specified by:
        findAllNearMissesFor in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • findNearMissesFor

        public List<com.github.tomakehurst.wiremock.verification.NearMiss> findNearMissesFor​(com.github.tomakehurst.wiremock.verification.LoggedRequest loggedRequest)
        Specified by:
        findNearMissesFor in interface com.github.tomakehurst.wiremock.junit.Stubbing
      • addStubMapping

        public void addStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)
        Specified by:
        addStubMapping in interface com.github.tomakehurst.wiremock.core.Admin
      • editStubMapping

        public void editStubMapping​(com.github.tomakehurst.wiremock.stubbing.StubMapping stubMapping)
        Specified by:
        editStubMapping in interface com.github.tomakehurst.wiremock.core.Admin
      • listAllStubMappings

        public com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult listAllStubMappings()
        Specified by:
        listAllStubMappings in interface com.github.tomakehurst.wiremock.core.Admin
      • getStubMapping

        public com.github.tomakehurst.wiremock.admin.model.SingleStubMappingResult getStubMapping​(UUID id)
        Specified by:
        getStubMapping in interface com.github.tomakehurst.wiremock.core.Admin
      • saveMappings

        public void saveMappings()
        Specified by:
        saveMappings in interface com.github.tomakehurst.wiremock.core.Admin
      • resetAll

        public void resetAll()
        Specified by:
        resetAll in interface com.github.tomakehurst.wiremock.core.Admin
      • resetRequests

        public void resetRequests()
        Specified by:
        resetRequests in interface com.github.tomakehurst.wiremock.core.Admin
      • resetToDefaultMappings

        public void resetToDefaultMappings()
        Specified by:
        resetToDefaultMappings in interface com.github.tomakehurst.wiremock.core.Admin
      • getServeEvents

        public com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult getServeEvents()
        Specified by:
        getServeEvents in interface com.github.tomakehurst.wiremock.core.Admin
      • getServedStub

        public com.github.tomakehurst.wiremock.admin.model.SingleServedStubResult getServedStub​(UUID id)
        Specified by:
        getServedStub in interface com.github.tomakehurst.wiremock.core.Admin
      • resetScenarios

        public void resetScenarios()
        Specified by:
        resetScenarios in interface com.github.tomakehurst.wiremock.core.Admin
      • resetMappings

        public void resetMappings()
        Specified by:
        resetMappings in interface com.github.tomakehurst.wiremock.core.Admin
      • countRequestsMatching

        public com.github.tomakehurst.wiremock.verification.VerificationResult countRequestsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)
        Specified by:
        countRequestsMatching in interface com.github.tomakehurst.wiremock.core.Admin
      • findRequestsMatching

        public com.github.tomakehurst.wiremock.verification.FindRequestsResult findRequestsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)
        Specified by:
        findRequestsMatching in interface com.github.tomakehurst.wiremock.core.Admin
      • findUnmatchedRequests

        public com.github.tomakehurst.wiremock.verification.FindRequestsResult findUnmatchedRequests()
        Specified by:
        findUnmatchedRequests in interface com.github.tomakehurst.wiremock.core.Admin
      • removeServeEvent

        public void removeServeEvent​(UUID uuid)
        Specified by:
        removeServeEvent in interface com.github.tomakehurst.wiremock.core.Admin
      • removeServeEventsMatching

        public com.github.tomakehurst.wiremock.verification.FindServeEventsResult removeServeEventsMatching​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)
        Specified by:
        removeServeEventsMatching in interface com.github.tomakehurst.wiremock.core.Admin
      • removeServeEventsForStubsMatchingMetadata

        public com.github.tomakehurst.wiremock.verification.FindServeEventsResult removeServeEventsForStubsMatchingMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern stringValuePattern)
        Specified by:
        removeServeEventsForStubsMatchingMetadata in interface com.github.tomakehurst.wiremock.core.Admin
      • updateGlobalSettings

        public void updateGlobalSettings​(com.github.tomakehurst.wiremock.global.GlobalSettings newSettings)
        Specified by:
        updateGlobalSettings in interface com.github.tomakehurst.wiremock.core.Admin
      • findNearMissesForUnmatchedRequests

        public com.github.tomakehurst.wiremock.verification.FindNearMissesResult findNearMissesForUnmatchedRequests()
        Specified by:
        findNearMissesForUnmatchedRequests in interface com.github.tomakehurst.wiremock.core.Admin
      • getAllScenarios

        public com.github.tomakehurst.wiremock.admin.model.GetScenariosResult getAllScenarios()
        Specified by:
        getAllScenarios in interface com.github.tomakehurst.wiremock.core.Admin
      • findTopNearMissesFor

        public com.github.tomakehurst.wiremock.verification.FindNearMissesResult findTopNearMissesFor​(com.github.tomakehurst.wiremock.verification.LoggedRequest loggedRequest)
        Specified by:
        findTopNearMissesFor in interface com.github.tomakehurst.wiremock.core.Admin
      • findTopNearMissesFor

        public com.github.tomakehurst.wiremock.verification.FindNearMissesResult findTopNearMissesFor​(com.github.tomakehurst.wiremock.matching.RequestPattern requestPattern)
        Specified by:
        findTopNearMissesFor in interface com.github.tomakehurst.wiremock.core.Admin
      • startRecording

        public void startRecording​(String targetBaseUrl)
        Specified by:
        startRecording in interface com.github.tomakehurst.wiremock.core.Admin
      • startRecording

        public void startRecording​(com.github.tomakehurst.wiremock.recording.RecordSpec spec)
        Specified by:
        startRecording in interface com.github.tomakehurst.wiremock.core.Admin
      • startRecording

        public void startRecording​(com.github.tomakehurst.wiremock.recording.RecordSpecBuilder recordSpec)
        Specified by:
        startRecording in interface com.github.tomakehurst.wiremock.core.Admin
      • stopRecording

        public com.github.tomakehurst.wiremock.recording.SnapshotRecordResult stopRecording()
        Specified by:
        stopRecording in interface com.github.tomakehurst.wiremock.core.Admin
      • getRecordingStatus

        public com.github.tomakehurst.wiremock.recording.RecordingStatusResult getRecordingStatus()
        Specified by:
        getRecordingStatus in interface com.github.tomakehurst.wiremock.core.Admin
      • snapshotRecord

        public com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord()
        Specified by:
        snapshotRecord in interface com.github.tomakehurst.wiremock.core.Admin
      • snapshotRecord

        public com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord​(com.github.tomakehurst.wiremock.recording.RecordSpecBuilder spec)
        Specified by:
        snapshotRecord in interface com.github.tomakehurst.wiremock.core.Admin
      • snapshotRecord

        public com.github.tomakehurst.wiremock.recording.SnapshotRecordResult snapshotRecord​(com.github.tomakehurst.wiremock.recording.RecordSpec spec)
        Specified by:
        snapshotRecord in interface com.github.tomakehurst.wiremock.core.Admin
      • getOptions

        public com.github.tomakehurst.wiremock.core.Options getOptions()
        Specified by:
        getOptions in interface com.github.tomakehurst.wiremock.core.Admin
      • shutdownServer

        public void shutdownServer()
        Specified by:
        shutdownServer in interface com.github.tomakehurst.wiremock.core.Admin
      • findAllStubsByMetadata

        public com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult findAllStubsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)
        Specified by:
        findAllStubsByMetadata in interface com.github.tomakehurst.wiremock.core.Admin
      • removeStubsByMetadata

        public void removeStubsByMetadata​(com.github.tomakehurst.wiremock.matching.StringValuePattern pattern)
        Specified by:
        removeStubsByMetadata in interface com.github.tomakehurst.wiremock.core.Admin
      • importStubs

        public void importStubs​(com.github.tomakehurst.wiremock.stubbing.StubImport stubImport)
        Specified by:
        importStubs in interface com.github.tomakehurst.wiremock.core.Admin
      • getGlobalSettings

        public com.github.tomakehurst.wiremock.admin.model.GetGlobalSettingsResult getGlobalSettings()
        Specified by:
        getGlobalSettings in interface com.github.tomakehurst.wiremock.core.Admin