Class WireMockRestServiceServer
java.lang.Object
org.springframework.cloud.contract.wiremock.WireMockRestServiceServer
Convenience class for loading WireMock stubs into a
MockRestServiceServer. In
this way using a RestTemplate can mock the responses from a server using
WireMock JSON DSL instead of the native Java DSL.- Author:
- Dave Syer
-
Method Summary
Modifier and TypeMethodDescriptionAdd a base url to all requests.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.Add some resource locations for files that represent response bodies.ignoreExpectOrder(boolean ignoreExpectOrder) Flag to tell the MockRestServiceServer to ignore the order of calls when matching requests.Add some resource locations for stubs.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 Details
-
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
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
Flag to tell the server to buffer the contents of the response.- Returns:
- this
-
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
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
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
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
-