Template for creating new WireMock extensions.
This template contains various samples on how you can write your own extension - just clone it and get started.
Not all parts are needed, thus feel free to adapt it. The code is documented and marked with TODO
comments to help
finding customization points.
Extensions can be explicitly configured or auto-detected. This extension supports auto-detection which eases integration in WireMock standalone or docker containers.
For supporting auto-detection as standalone library, this template implements the Java Service Provider Interface, which is used by WireMock to find extensions and packages everything using shadowjar.
When forking this repository, you have to adapt shadowjar/resources/META-INF/services/com.github.tomakehurst.wiremock.extension.ExtensionFactory
to point to a class with default constructor which registers all parts of your extension
(in this template, this is handled by org.wiremock.extensions.template.StandaloneTemplateExtension
).
For non-standalone usages, you can use your own class to instantiate your extension. In this template,
this is handled by org.wiremock.extensions.template.TemplateExtension
. Having the standalone version using this one
helps ensuring a consistent extension setup.
Official documentation on using request matchers: https://wiremock.org/docs/request-matching/ Official documentation on creating request matchers extension: https://wiremock.org/docs/extensibility/custom-matching/
The sample code in this template shows how to read parameters and values which contain handlebar templates to get similar functionalities as when using them in response templates.
See org.wiremock.extensions.template.extensions.RequestMatcher
for a sample and org.wiremock.extensions.template.RequestMatcherTest
for a corresponding test.