Class WireMockRestServiceServer
- java.lang.Object
-
- org.springframework.cloud.contract.wiremock.WireMockRestServiceServer
-
public final class WireMockRestServiceServer extends Object
Convenience class for loading WireMock stubs into aMockRestServiceServer. In this way using aRestTemplatecan mock the responses from a server using WireMock JSON DSL instead of the native Java DSL.- Author:
- Dave Syer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WireMockRestServiceServerbaseUrl(String baseUrl)Add a base url to all requests.WireMockRestServiceServerbufferContent()Flag to tell the server to buffer the contents of the response.org.springframework.test.web.client.MockRestServiceServerbuild()Build a MockRestServiceServer from the configured stubs.WireMockRestServiceServerfiles(String... locations)Add some resource locations for files that represent response bodies.WireMockRestServiceServerignoreExpectOrder(boolean ignoreExpectOrder)Flag to tell the MockRestServiceServer to ignore the order of calls when matching requests.WireMockRestServiceServerstubs(String... locations)Add some resource locations for stubs.WireMockRestServiceServersuffix(String suffix)If stub locations are given as a directory, then we search recursively in that directory for files with this suffix.static WireMockRestServiceServerwith(org.springframework.web.client.RestTemplate restTemplate)Public factory method for wrapping a rest template into a MockRestServiceServer.
-
-
-
Method Detail
-
with
public static WireMockRestServiceServer with(org.springframework.web.client.RestTemplate restTemplate)
Public factory method for wrapping a rest template into a MockRestServiceServer.- Parameters:
restTemplate- the rest template to wrap- Returns:
- a WireMockRestServiceServer
-
ignoreExpectOrder
public WireMockRestServiceServer ignoreExpectOrder(boolean ignoreExpectOrder)
Flag to tell the MockRestServiceServer to ignore the order of calls when matching requests. The default is true because there is an implied ordering in the stubs (by url path and with more specific request matchers first).- Parameters:
ignoreExpectOrder- flag value (default true)- Returns:
- this
-
bufferContent
public WireMockRestServiceServer bufferContent()
Flag to tell the server to buffer the contents of the response.- Returns:
- this
-
suffix
public WireMockRestServiceServer suffix(String suffix)
If stub locations are given as a directory, then we search recursively in that directory for files with this suffix. Default is ".json".- Parameters:
suffix- the suffix to use when creating a resource pattern- Returns:
- this
-
baseUrl
public WireMockRestServiceServer baseUrl(String baseUrl)
Add a base url to all requests. Most WireMock JSON stubs have a path, but no protocol or host in the request matcher, so this is useful when your rest template is calling to a specific host.- Parameters:
baseUrl- a base url to apply- Returns:
- this
-
stubs
public WireMockRestServiceServer stubs(String... locations)
Add some resource locations for stubs. Each location can be a resource path (to a single JSON file), or a pattern with ant-style wildcards to load all stubs that match, or a plain directory name (which will have**/*.jsonappended, where ".json" is the value of thesuffix). Examples:classpath:/mappings/foo.json classpath:/mappings/*.json classpath:META-INF/com.example/stubs/1.0.0/mappings/**/*.json file:src/test/resources/stubs
- Parameters:
locations- a set of resource locations- Returns:
- this
-
files
public WireMockRestServiceServer files(String... locations)
Add some resource locations for files that represent response bodies. Wiremock defaults to "file:src/test/resources/__files".- Parameters:
locations- locations with files- Returns:
- this
-
build
public org.springframework.test.web.client.MockRestServiceServer build()
Build a MockRestServiceServer from the configured stubs. The server can later be verified (optionally), if you need to check that all expected requests were made.- Returns:
- a MockRestServiceServer
-
-