Introduced adding of custom WireMock extensions (#429)

without this change we set only a single extension "response-transformer" without an option to provide any other ones
with this change we introduce the "spring.factories" based extension model. It's enough to provide your own implementation of `org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions` and register it in `spring.factories`. That way you can control all extensions (request / response).

fixes #425
This commit is contained in:
Marcin Grzejszczak
2017-10-05 15:52:27 +02:00
committed by GitHub
parent 4a46760ee2
commit 0758f4ec38
12 changed files with 271 additions and 57 deletions

View File

@@ -536,6 +536,31 @@ proper values. Additionally, it registers two helper functions:
* `escapejsonbody`: Escapes the request body in a format that can be embedded in a JSON.
* `jsonpath`: For a given parameter, find an object in the request body.
==== Registering Your Own WireMock Extension
WireMock lets you register custom extensions. By default, Spring Cloud Contract registers
the transformer, which lets you reference a request from a response. If you want to
provide your own extensions, you can register an implementation of the
`org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions` interface.
Since we use the spring.factories extension approach, you can create an entry in
`META-INF/spring.factories` file similar to the following:
[source,groovy,indent=0]
----
include::{stubrunner_core_path}/src/test/resources/META-INF/spring.factories[indent=0]
----
The following is an example of a custom extension:
.TestWireMockExtensions.groovy
[source,groovy,indent=0]
----
include::{stubrunner_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/TestWireMockExtensions.groovy[indent=0]
----
IMPORTANT: Remember to override the `applyGlobally()` method and set it to `false` if you
want the transformation to be applied only for a mapping that explicitly requires it.
==== Dynamic Properties in the Matchers Sections
If you work with https://docs.pact.io/[Pact], the following discussion may seem familiar.